Bryant Conquest Bryant Conquest - 2 months ago 6
Python Question

I am trying to make a lcd program so that all the numbers are printed side by side and its not working

I am trying to print out ascii numbers side by side in python after the previous number is printed. If I put a comma after the last line in the function only the top part of the next number is printed.

def zero():
print " __ "
print "| |"
print "|__|"

def one():
print " "
print " |"
print " |"

def two():
print " __ "
print " __|"
print "|__ "

def three():
print " __ "
print " __|"
print " __|"

def four():
print "|_|"
print " |"

def five():
print " __ "
print "|__ "
print " __|"

def six():
print " __ "
print "|__ "
print "|__|"

def seven():
print " __ "
print " |"
print " |"

def eight():
print " __ "
print "|__|"
print "|__|"

def nine():
print " __ "
print "|__|"
print " |"



x = raw_input("Type the number you would like printed: ")
a = list(x)
for x in a:
if x == '1':
one(),
elif x == '2':
two(),
elif x == '3':
three(),
elif x == '4':
four(),
elif x == '5':
five(),
elif x == '6':
six(),
elif x == '7':
seven(),
elif x == '8':
eight(),
elif x == '9':
nine(),
elif x == '0':
zero(),
elif x == 'Quit':
break
else:
print "Number not entered"

Answer

funny exercice :)

following the comments of @zvone perhaps something like this:

def zero():
    chars  = [" __ "]
    chars += ["|  |"]
    chars += ["|__|"]
    return chars

def one():
    chars  = ["    "]
    chars += ["   |"]
    chars += ["   |"]
    return chars

def two():
    chars  = [" __ "]
    chars += [" __|"]
    chars += ["|__ "]
    return chars

def three():
    chars  = [" __ "]
    chars += [" __|"]
    chars += [" __|"]
    return chars

def four():
    chars  = ["   "]
    chars += ["|_|"]
    chars += ["  |"]
    return chars

def five():
    chars  = [" __ "]
    chars += ["|__ "]
    chars += [" __|"]
    return chars

def six():
    chars  = [" __ "]
    chars += ["|__ "]
    chars += ["|__|"]
    return chars

def seven():
    chars  = ["  __ "]
    chars += ["    |"]
    chars += ["    |"]
    return chars

def eight():
    chars  = [" __ "]
    chars += ["|__|"]
    chars += ["|__|"]
    return chars

def nine():
    chars  = [" __ "]
    chars += ["|__|"]
    chars += ["   |"]
    return chars

numbers = {'0': zero,
           '1': one,
           '2': two,
           '3': three,
           '4': four,
           '5': five,
           '6': six,
           '7': seven,
           '8': eight,
           '9': nine}

def print_lcd(a):
    for line in zip(*[numbers[num]() for num in a]):
        print ' '.join(line)
    else:
        print "Number not entered"

x = raw_input("Type the number you would like printed: ")
a = list(x)
print_lcd(a)
Comments