Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
English to Braille Translator solution in Uncategorized category for English to Braille Translator by capback250
from math import ceil
alfa = {
'a':((1,0),(0,0),(0,0)),
'b':((1,0),(1,0),(0,0)),
'c':((1,1),(0,0),(0,0)),
'd':((1,1),(0,1),(0,0)),
'e':((1,0),(0,1),(0,0)),
'f':((1,1),(1,0),(0,0)),
'g':((1,1),(1,1),(0,0)),
'h':((1,0),(1,1),(0,0)),
'i':((0,1),(1,0),(0,0)),
'j':((0,1),(1,1),(0,0)),
'k':((1,0),(0,0),(1,0)),
'l':((1,0),(1,0),(1,0)),
'm':((1,1),(0,0),(1,0)),
'n':((1,1),(0,1),(1,0)),
'o':((1,0),(0,1),(1,0)),
'p':((1,1),(1,0),(1,0)),
'q':((1,1),(1,1),(1,0)),
'r':((1,0),(1,1),(1,0)),
's':((0,1),(1,0),(1,0)),
't':((0,1),(1,1),(1,0)),
'u':((1,0),(0,0),(1,1)),
'v':((1,0),(1,0),(1,1)),
'x':((1,1),(0,0),(1,1)),
'y':((1,1),(0,1),(1,1)),
'z':((1,0),(0,1),(1,1)),
'w':((0,1),(1,1),(1,1)),
' ':((0,0),(0,0),(0,0)),
'1':((1,0),(0,0),(0,0)),
'2':((1,0),(1,0),(0,0)),
'3':((1,1),(0,0),(0,0)),
'4':((1,1),(0,1),(0,0)),
'5':((1,0),(0,1),(0,0)),
'6':((1,1),(1,0),(0,0)),
'7':((1,1),(1,1),(0,0)),
'8':((1,0),(1,1),(0,0)),
'9':((0,1),(1,0),(0,0)),
'0':((0,1),(1,1),(0,0)),
',':((0,0),(1,0),(0,0)),
'.':((0,0),(1,1),(0,1)),
'-':((0,0),(1,1),(0,0)),
'?':((0,0),(1,0),(1,1)),
'_':((0,0),(0,0),(1,1)),
'!':((0,0),(1,1),(1,0)),
'capital':((0,0),(0,0),(0,1)),
'number':((0,1),(0,1),(1,1)),
'zero':((0,0),(0,0),(0,0))
}
def braille_page(string):
output = []
final = []
for letter in string:
if letter.isupper():
output.append(alfa['capital'])
output.append(alfa[letter.lower()])
elif letter.isdigit():
output.append(alfa['number'])
output.append(alfa[letter])
else:
output.append(alfa[letter])
if len(output) <= 10:
for j in range(3):
t = []
for i in output:
t.extend([i[j][0], i[j][1], 0])
final.append(t[:-1])
else:
for _ in range(int(ceil(len(output) / 10.0))*10 - len(output)):
output.append(alfa['zero'])
max_st = int(ceil(len(output) / 10.0)) - 1
for x in range(0, len(output), 10):
for j in range(3):
temp = []
for i in output[x:x+10]:
if len(temp) != 27:
temp.extend([i[j][0], i[j][1], 0])
else:
temp.extend([i[j][0], i[j][1]])
final.append(temp)
if max_st:
final.append([0]*29)
max_st -= 1
return final
Jan. 5, 2016