So the program works like this, i need to input a number and once my program identifies the number in the class it will print the given number in LCD format (7-segment display).
class lcd:
def numbers():
0 = ["_","| |","_"]
1 = ["|","|","|"]
2 = ["_","_|","|_"]
3 = ["_","_|","_|"]
4 = ["|_|"," |"]
5 = ["_","|_"," _|"]
6 = ["_","|_","|_|"]
7 = ["_"," |"," |"]
8 = ["_","|_|","|_|"]
9 = [" _","|_|"," _|"]
def numgen(num):
print("Type the number you want to print in LCD: ")
num = lcd()
for i in range (lcd):
if hasattr(num,'numbers'):
for i in range (3):
print("\n")
return
if __name__ == '__main__':
num = int(input())
numgen()
print(num)
The problem is that I don't know how can I proceed, i've been reading some functions but none of them works. I tried as you can see a weird way with hasattr but obviously it didn't work. In the last loop I tried to print that space for each object in my attributes, so in that way the number will print correctly. I will much appreciate any help.
CodePudding user response:
IIUC, you want to print numbers in LCD format (or rather 7 segments).
Here is a minimal code for it. The most important part is to use zip
to build the lines.
NB. I had to fix your digit segments that were incorrect.
digits = {
0 : [" _ ","| |","|_|"],
1 : [" ","|","|"],
2 : [" _ "," _|","|_ "],
3 : ["_ ","_|","_|"],
4 : [" ", "|_|"," |"],
5 : [" _ ","|_ "," _|"],
6 : [" _ ","|_ ","|_|"],
7 : ["_ "," |"," |"],
8 : [" _ ","|_|","|_|"],
9 : [" _ ","|_|"," _|"],}
def print_num(num):
parts = [digits[int(d)] for d in str(num)]
print('\n'.join(' '.join(line) for line in zip(*parts)))
print_num(1234567890)
Output:
_ _ _ _ _ _ _ _
| _| _| |_| |_ |_ | |_| |_| | |
| |_ _| | _| |_| | |_| _| |_|