-
Notifications
You must be signed in to change notification settings - Fork 0
/
braille.py
58 lines (53 loc) · 1.26 KB
/
braille.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
class Braille:
space = '000000'
upper = '000001'
alpha = [
'100000', # a
'110000', # b
'100100', # c
'100110', # d
'100010', # e
'110100', # f
'110110', # g
'110010', # h
'010100', # i
'010110', # j
'101000', # k
'111000', # l
'101100', # m
'101110', # n
'101010', # o
'111100', # p
'111110', # q
'111010', # r
'011100', # s
'011110', # t
'101001', # u
'111001', # v
'010111', # w
'101101', # x
'101111', # y
'101011', # z
]
@staticmethod
def get_value(c: chr) -> str:
if c == ' ':
return Braille.space
diff = 0
s = ''
if c >= 'A' and c <= 'Z':
diff = ord(c) - ord('A')
s += Braille.upper
else:
diff = ord(c) - ord('a')
s += Braille.alpha[diff]
return s
def solution(plaintext):
characters = list(plaintext.strip())
braille = [Braille.get_value(c) for c in characters]
return ''.join(braille)
if __name__ == "__main__":
plaintext1 = "code"
print(solution(plaintext1))
plaintext2 = "Braille"
print(solution(plaintext2))