Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to get the seven segment output side by side in python?

I have written a code to display the seven segment output. Whereas I need to display the output side by side.
Say input: 123 , output should display seven segment side by side as below

#  ### ###   
#    #   #
#  ### ###
#  #     #
#  ### ###

Here is my logic:

dict = {0:('###','# #','# #','# #','###'),
        1:('  #','  #','  #','  #','  #'),
        2:('###','  #','###','#  ','###'),
        3:('###','  #','###','  #','###'),
        4:('#  ','#  ','###','  #','  #'),
        5:('###','#  ','###','  #','###'),
        6:('###','#  ','###','#  ','###'),
        7:('###','  #','  #','  #','  #'),
        8:('###','# #','###','# #','###')}
value = input("enter value:")
for i in value:
    list1 = dict.get(int(i))
    print('\n'.join(list1))

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Try the following:

dict = {0:('###','# #','# #','# #','###'),
        1:('  #','  #','  #','  #','  #'),
        2:('###','  #','###','#  ','###'),
        3:('###','  #','###','  #','###'),
        4:('#  ','#  ','###','  #','  #'),
        5:('###','#  ','###','  #','###'),
        6:('###','#  ','###','#  ','###'),
        7:('###','  #','  #','  #','  #'),
        8:('###','# #','###','# #','###')}
value = input("enter value:")
for seg in range(5):
    print(' '.join([dict.get(int(i))[seg] for i in value]))

You need to print the segments side by side, so you should start by printing the top column of all the numbers, the second, and so on.
I’m using a list comprehension to join the numbers together for each column.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading