-
Notifications
You must be signed in to change notification settings - Fork 1
/
seven-segment.py
166 lines (141 loc) · 4.29 KB
/
seven-segment.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Jun 28 16:50:45 2019
@author: martandsingh
"""
import numpy as np
rows = 13
cols = 10
top_half, bottom_half_left, top_half_right, bottom_half_right, top, bottom = int(rows/2), rows - int(rows/2), int(rows/2), rows - int(rows/2), cols, cols
#print(top_half_right, bottom_half_right)
A = [[' ' for x in range(cols)] for x in range(rows)]
def intro():
_hyphen = '-'*5
print(_hyphen + "welcome to the codemaker".capitalize() + _hyphen)
print("A small program to implement seven segment numbers, which you all must have seen in digital clocks.")
print("\nThis program will print a given number in seven segment form. It doesnt support multiple digit for now.")
print("\nYou can download script from github repo mentioned in description.")
print("\nAlso follow us on facebook: https://www.facebook.com/codemakerz")
print("\n\n\n This script is not filtered. You may find some unused variables.")
print(_hyphen + "Thank You..."+ _hyphen)
def get_array():
return [[' ' for x in range(cols)] for x in range(rows)]
def show_top_left_half(A):
for i in range(top_half):
for j in range(1):
# if(i%2 != 0):
A[i][j] = '*'
def show_bottom_left_half(A):
for i in range(bottom_half_left, rows-1):
for j in range(1):
# if(i%2 != 0):
A[i][j] = '*'
def show_top_right_half(A):
for i in range(top_half):
for j in range(cols-1, cols):
A[i][j] = '*'
def show_bottom_right_half(A):
for i in range(bottom_half_left, rows-1):
for j in range(cols-1, cols):
A[i][j] = '*'
def show_top(A):
for i in range(1):
for j in range(cols):
A[i][j] = '*'
def show_bottom(A):
for i in range(1):
for j in range(cols):
A[rows-1][j] = '*'
def show_middle(A):
for i in range(top_half, top_half+1):
for j in range(cols):
A[i][j] = "*"
def show_left_middle_dot(A):
A[top_half][0] = "*"
def show_right_middle_dot(A):
A[top_half][cols-1] = "*"
def print_number(val):
A = get_array()
if val == 1:
show_top_right_half(A)
show_bottom_right_half(A)
show_right_middle_dot(A)
elif val == 2:
show_top(A)
show_bottom(A)
show_top_right_half(A)
show_middle(A)
show_bottom_left_half(A)
elif val == 3:
show_top(A)
show_bottom(A)
show_top_right_half(A)
show_middle(A)
show_bottom_right_half(A)
elif val == 4:
show_top_left_half(A)
show_middle(A)
show_top_right_half(A)
show_bottom_right_half(A)
elif val == 5:
show_top(A)
show_bottom(A)
show_top_left_half(A)
show_bottom_right_half(A)
show_middle(A)
elif val == 6:
show_bottom(A)
show_middle(A)
show_top_left_half(A)
show_bottom_left_half(A)
show_bottom_right_half(A)
elif val == 7:
show_top(A)
show_top_right_half(A)
show_bottom_right_half(A)
show_right_middle_dot(A)
elif val == 8:
show_top(A)
show_middle(A)
show_bottom(A)
show_top_left_half(A)
show_bottom_left_half(A)
show_top_right_half(A)
show_bottom_right_half(A)
elif val == 9:
show_top(A)
show_middle(A)
show_bottom(A)
show_top_left_half(A)
show_top_right_half(A)
show_bottom_right_half(A)
elif val == 0:
show_top(A)
show_bottom(A)
show_top_left_half(A)
show_bottom_left_half(A)
show_top_right_half(A)
show_bottom_right_half(A)
show_left_middle_dot(A)
show_right_middle_dot(A)
for i in range(rows):
for j in range(cols):
print(A[i][j], end=''*3)
print('')
def main():
is_exit = False
intro()
while True:
if(is_exit):
exit()
else:
num = input("enter single digit to print in digital format. Press 'y' to exit: ")
if num.lower() == 'y':
is_exit = True
else:
num = int(num)
print("\n")
print(print_number(num))
print("\n")
main()