-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathseven_seg.py
More file actions
37 lines (33 loc) · 1.21 KB
/
seven_seg.py
File metadata and controls
37 lines (33 loc) · 1.21 KB
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
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
""" Seven seg module """
__copyright__ = "Copyright 2015, Matthieu Velay"
SEVEN_SEG_DICT = {
"0": (" _ ", "| |", "|_|"),
"1": (" ", " |", " |"),
"2": (" _ ", " _|", "|_ "),
"3": (" _ ", " _|", " _|"),
"4": (" ", "|_|", " |"),
"5": (" _ ", "|_ ", " _|"),
"6": (" _ ", "|_ ", "|_|"),
"7": (" _ ", " |", " |"),
"8": (" _ ", "|_|", "|_|"),
"9": (" _ ", "|_|", " _|")
}
def seven_seg(input_string):
"""
@goal: given a string return the seven segment output
@param input_string: integer we want to display as seven-seg way
@return output_string: seven-seg converted string
"""
try:
int(input_string)
output_string = ''
seven_list = [ SEVEN_SEG_DICT[number] for number in input_string ]
for index in range(3):
for pos in range(len(input_string)):
output_string += ''.join(seven_list[pos][index])
output_string += '\n'
except ValueError as exc:
raise exc
return output_string