Python Forum

Full Version: Seven Segment Display - QUERY on Multi-line side-by-side printing output
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Task - a program which is able to simulate the work of a seven-display device

Sample input:

123

Sample output:

Output:
# ### ### # # # # ### ### # # # # ### ###
So far....
printE = (" \n \n \n \n \n")
print0 = ("###\n# #\n# #\n# #\n###\n")
print1 = ("  #\n"*5)
print2 = ("###\n  #\n###\n#  \n###\n")
print3 = ("###\n  #\n###\n  #\n###\n")
print4 = ("# #\n# #\n###\n  #\n  #\n")
print5 = ("###\n#  \n###\n  #\n###\n")
print6 = ("###\n#  \n###\n# #\n###\n")
print7 = ("###\n  #\n  #\n  #\n  #\n")
print8 = ("###\n# #\n###\n# #\n###\n")
print9 = ("###\n# #\n# #\n  #\n###\n")

printList = [print0,print1,print2,print3,print4,print5,print6,print7,print8,print9]

inputVal = int(input("Enter an integer :"))
inputStr = str(inputVal)
inputDigits = [int(x) for x in inputStr]

# print (len(inputStr))
# print(inputDigits)
result = ""

for i in inputDigits:
    result += printList[i]
print (result)
This outputs

Output:
# # # # # ### # ### # ### ### # ### # ###
Is there an easy way to achieve this output printed side-by-side.
(I did read some information on using zip but I suppose there should/could be an easier way to print the lines.)

Any help is appreciated. Shy
This looks like a very promising write-up: http://www.python-exemplary.com/index_en...ys.inc.php
You can set separator for print:

>>> print('ab', 'cd', sep=' ')                                                     
ab cd
One way is to construct number representations and then print them row by row. As this is homework I would give just an idea:

>>> first = ['###', '  #']
>>> second = ['#', '#']
>>> print(*first, sep='\n')                                                         
###
  #
>>> print(*second, sep='\n')
#
#
>>> for i in range(2):        # height of 'symbols', in this case 2 items/rows
...     print(first[i], second[i], sep=' ')
...
### #
  # #
(Mar-11-2020, 08:33 PM)Larz60+ Wrote: [ -> ]This looks like a very promising write-up: http://www.python-exemplary.com/index_en...ys.inc.php

Thanks, Larz Wink but at this moment, I am not yet into doing this through a PI.(I did go through it however)
This was just a basic coding exercise to display the enetered numeric value as a 'seven segment display'

(Mar-12-2020, 11:25 AM)perfringo Wrote: [ -> ]You can set separator for print:

>>> print('ab', 'cd', sep=' ')                                                     
ab cd
One way is to construct number representations and then print them row by row. As this is homework I would give just an idea:

>>> first = ['###', '  #']
>>> second = ['#', '#']
>>> print(*first, sep='\n')                                                         
###
  #
>>> print(*second, sep='\n')
#
#
>>> for i in range(2):        # height of 'symbols', in this case 2 items/rows
...     print(first[i], second[i], sep=' ')
...
### #
  # #


Thank you perfringo Smile
Set it as a line-by-line print for each digit and used a double array nad it worked perfect. Dance

print0 = ("###","# #","# #","# #","###")
print1 = ("  #","  #","  #","  #","  #")
print2 = ("###","  #","###","#  ","###")
print3 = ("###","  #","###","  #","###")
print4 = ("# #","# #","###","  #","  #")
print5 = ("###","#  ","###","  #","###")
print6 = ("###","#  ","###","# #","###")
print7 = ("###","  #","  #","  #","  #")
print8 = ("###","# #","###","# #","###")
print9 = ("###","# #","###","  #","###")

printList = [print0,print1,print2,print3,print4,print5,print6,print7,print8,print9]

inputVal = int(input("Enter an integer :"))
inputStr = str(inputVal)
inputDigits = [int(x) for x in inputStr]



for j in range(5):
    result =""
    for i in inputDigits:
        result += printList[i][j]+" "
    print (result, sep="\n")
Output:
Enter an integer :50674 ### ### ### ### # # # # # # # # # ### # # ### # ### # # # # # # # ### ### ### # # >>>