Skip to content

Commit d880ee8

Browse files
committed
Solution to Issue the-vampiire#14.
1 parent 4c1a3e4 commit d880ee8

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
"""Solution to Issue #14 (Braille Translation)."""
2+
3+
braille_table = {
4+
'a': '100000',
5+
'b': '110000',
6+
'c': '100100',
7+
'd': '100110',
8+
'e': '100010',
9+
'f': '110100',
10+
'g': '110110',
11+
'h': '110010',
12+
'i': '010100',
13+
'j': '010110',
14+
'k': '101000',
15+
'l': '111000',
16+
'm': '101100',
17+
'n': '101110',
18+
'o': '101010',
19+
'p': '111100',
20+
'q': '111110',
21+
'r': '111010',
22+
's': '011100',
23+
't': '011110',
24+
'u': '101001',
25+
'v': '111001',
26+
'w': '010111',
27+
'x': '101101',
28+
'y': '101111',
29+
'z': '101011',
30+
' ': '000000',
31+
'CAP': '000001',
32+
}
33+
34+
test_cases = {
35+
'code': '100100101010100110100010',
36+
'Braille': '000001110000111010100000010100111000111000100010',
37+
'The quick brown fox jumped over the lazy dog':
38+
'''00000101111011001010001000000011111010100101010010010010100000000011\
39+
0000111010101010010111101110000000110100101010101101000000010110101001101100111\
40+
1001000101001100000001010101110011000101110100000000111101100101000100000001110\
41+
00100000101011101111000000100110101010110110'''
42+
}
43+
44+
45+
def translate(string):
46+
"""Translate plain-text to braille."""
47+
braille_code = []
48+
for i in string:
49+
if i.isupper():
50+
braille_code.append(braille_table['CAP'])
51+
braille_code.append(braille_table[i.lower()])
52+
continue
53+
braille_code.append(braille_table[i])
54+
return ''.join(braille_code)
55+
56+
57+
def test():
58+
"""Actual Function."""
59+
for item, value in test_cases.items():
60+
try:
61+
assert(translate(item) == value)
62+
except AssertionError:
63+
print(item, value, translate(item), sep='\n')
64+
continue
65+
print('Tests Passed.')
66+
67+
68+
def main():
69+
"""Actual Function."""
70+
string = input()
71+
print(translate(string))
72+
73+
74+
if __name__ == '__main__':
75+
main()

0 commit comments

Comments
 (0)