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
JavaScript
x
6
1
# ### ###
2
# # #
3
# ### ###
4
# # #
5
# ### ###
6
Here is my logic:
JavaScript
1
14
14
1
dict = {0:('###','# #','# #','# #','###'),
2
1:(' #',' #',' #',' #',' #'),
3
2:('###',' #','###','# ','###'),
4
3:('###',' #','###',' #','###'),
5
4:('# ','# ','###',' #',' #'),
6
5:('###','# ','###',' #','###'),
7
6:('###','# ','###','# ','###'),
8
7:('###',' #',' #',' #',' #'),
9
8:('###','# #','###','# #','###')}
10
value = input("enter value:")
11
for i in value:
12
list1 = dict.get(int(i))
13
print('n'.join(list1))
14
Advertisement
Answer
Try the following:
JavaScript
1
13
13
1
dict = {0:('###','# #','# #','# #','###'),
2
1:(' #',' #',' #',' #',' #'),
3
2:('###',' #','###','# ','###'),
4
3:('###',' #','###',' #','###'),
5
4:('# ','# ','###',' #',' #'),
6
5:('###','# ','###',' #','###'),
7
6:('###','# ','###','# ','###'),
8
7:('###',' #',' #',' #',' #'),
9
8:('###','# #','###','# #','###')}
10
value = input("enter value:")
11
for seg in range(5):
12
print(' '.join([dict.get(int(i))[seg] for i in value]))
13
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.