用python实现七段数码管
时间: 2023-07-12 14:28:48 浏览: 79
好的,以下是Python实现七段数码管的代码:
```python
digit = {
'0': ['1111110', '1000010', '1000010', '1000010', '1000010', '1000010', '1111110'],
'1': ['0110000', '0010000', '0010000', '0010000', '0010000', '0010000', '0111000'],
'2': ['1111110', '0000010', '0000010', '1111110', '1000000', '1000000', '1111110'],
'3': ['1111110', '0000010', '0000010', '1111110', '0000010', '0000010', '1111110'],
'4': ['1000010', '1000010', '1000010', '1111110', '0000010', '0000010', '0000010'],
'5': ['1111110', '1000000', '1000000', '1111110', '0000010', '0000010', '1111110'],
'6': ['1111110', '1000000', '1000000', '1111110', '1000010', '1000010', '1111110'],
'7': ['1111110', '0000010', '0000010', '0000010', '0000010', '0000010', '0000010'],
'8': ['1111110', '1000010', '1000010', '1111110', '1000010', '1000010', '1111110'],
'9': ['1111110', '1000010', '1000010', '1111110', '0000010', '0000010', '1111110']
}
def print_seven_segment(digit_str):
for i in range(7):
for j in range(len(digit_str)):
print(digit[digit_str[j]][i], end=' ')
print()
# 测试
print_seven_segment('0123456789')
```
这个程序使用了一个名为`digit`的字典,其中每个数字都有一个对应的七段数码管的表示方式。`print_seven_segment`函数接受一个数字字符串作为参数,然后按照行的顺序打印出这个数字字符串的每个数字的七段数码管表示。
阅读全文