Skip to content

Commit

Permalink
Braille Translation the-vampiire#14 solution
Browse files Browse the repository at this point in the history
  • Loading branch information
minhduccao committed Oct 27, 2019
1 parent 6eb5472 commit 28e74c1
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions python/tough_stuff/braille-translation_minhduccao.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Based on final instructions and test cases by aidanconnolly
# Assumes plain text string without punctuation
def brailleTrans(s):
"""Translates a non-punctuated string into braille"""
# Dictionary of conversions is required because going from letters to braille
# isn't based on a pattern unlike binary
brailleAlphabet = {
'CAPS': '000001', # Signifies capitalization
' ': '000000', # Space character
'a': '100000',
'b': '110000',
'c': '100100',
'd': '100110',
'e': '100010',
'f': '110100',
'g': '110110',
'h': '110010',
'i': '010100',
'j': '010110',
'k': '101000',
'l': '111000',
'm': '101100',
'n': '101110',
'o': '101010',
'p': '111100',
'q': '111110',
'r': '111010',
's': '011100',
't': '011110',
'u': '101001',
'v': '111001',
'w': '010111',
'x': '101101',
'y': '101111',
'z': '101011'
}

letters = list(s) # Change word into list of letters
out = ''
for letter in letters: # Letter-by-letter translation
if letter.isupper(): # Checks if letter is capitalized to insert capital character
out += brailleAlphabet['CAPS']
out += brailleAlphabet[letter.lower()]
return out

0 comments on commit 28e74c1

Please sign in to comment.