Python Forum
Seven Segment Display - QUERY on Multi-line side-by-side printing output
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Seven Segment Display - QUERY on Multi-line side-by-side printing output
#1
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
Reply
#2
This looks like a very promising write-up: http://www.python-exemplary.com/index_en...ys.inc.php
Reply
#3
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=' ')
...
### #
  # #
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply
#4
(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 ### ### ### ### # # # # # # # # # ### # # ### # ### # # # # # # # ### ### ### # # >>>
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Display 8 elements per line SalsaBeanDip 1 1,592 Oct-06-2020, 02:24 AM
Last Post: deanhystad
  exception in side if clause sbabu 6 2,969 Feb-15-2020, 08:44 AM
Last Post: ndc85430
  Printing on same line from 2 functions. Dyefull 2 2,259 Dec-05-2019, 07:39 AM
Last Post: ndc85430
  Blank spaces in right side fernando_santiago18 1 1,607 Sep-07-2019, 12:33 PM
Last Post: ThomasL
  finding p's in words of a multi-line text file johneven 5 4,356 Jun-24-2019, 03:41 PM
Last Post: ThomasL
  reading text file and writing to an output file precedded by line numbers kannan 7 10,374 Dec-11-2018, 02:19 PM
Last Post: ichabod801
  Command line inputs not printing to Log File ijosefson 1 3,351 Oct-19-2017, 06:41 AM
Last Post: buran
  Skipping a line on output lucas0150 3 3,879 Apr-27-2017, 04:32 PM
Last Post: Ofnuts

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020