-1

Im working on a translator (english to braille) as a project for a class in python 2.7. We've been essentially thrown to the wolves and I've never had experience coding before. How in the hell am I supposed to create a function that iterates through one dictionary and spits out the value for each letter in english(only one dictionary so I get the general idea)?

Ive got a comfortable 3 dictionaries for each row that a braille letter takes to make, and im honestly just not sure where to start in terms of the function. Ive got a prompt asking for a word, but idk how to make python look at individual letters in a word and reference those letters to a dictionary.

eng_to_braille_1 = {
  'a': '. ', 'b': '. ', 'c': '..', 'd': '..', 'e': '. ', 'f': '..', 'g': '..', 'h': '. ', 'i': ' .', 'j': ' .', 'k': '. ', 'l': '. ', 'm': '..', 'n': '..', 'o': '. ', 'p': '..', 'q': '..', 'r': '. ', 's': ' .','t': ' .', 'u': '. ', 'v': '. ', 'x': '..', 'y': '..', 'z': '. '
}

eng_to_braille_2 = {
  'a': '  ', 'b': '. ', 'c': '  ', 'd': ' .', 'e': ' .', 'f': '. ', 'g': '..', 'h': '..', 'i': '. ', 'j': '..', 'k': '  ', 'l': '. ', 'm': '  ', 'n': ' .', 'o': ' .', 'p': '. ', 'q': '..', 'r': '..', 's': '. ','t': '..', 'u': '  ', 'v': '. ', 'x': '  ', 'y': ' .', 'z': ' .'
}

eng_to_braille_3 = {
  'a': '  ', 'b': '  ', 'c': '  ', 'd': '  ', 'e': '  ', 'f': '  ', 'g': '  ', 'h': '  ', 'i': '  ', 'j': '  ', 'k': '. ', 'l': '. ', 'm': '. ', 'n': '. ', 'o': '. ', 'p': '. ', 'q': '. ', 'r': '. ', 's': '. ','t': '. ', 'u': '..', 'v': '..', 'x': '..', 'y': '..', 'z': '..'
}

word = input("Type a word to be translated: ")
word = str()

def translate(word):
   translation = ""
snakecharmerb
  • 47,570
  • 11
  • 100
  • 153
  • 2
    Why are there three dictionaries? Does braille have different representations of the same letter, depending on some criterion? – snakecharmerb Sep 08 '19 at 17:37
  • Is creating one dictionary from these 3 allowed? BTW you don't need to iterate. Dictionary is a key-value storage. You can access each of them by key. – Tom Wojcik Sep 08 '19 at 17:41
  • @AddoExitium Not everybody knows how Braille works. Also you have the translation of each letter scattered across three different data structures, which is weird because I would expect you to want the whole translation of a letter, not a particular row of it. Besides, if you are stuck with the problem of looking at individual letters in a word, everything about dictionaries and Braille is pretty much irrelevant to you at this point. You'd better solve your problems one by one. – Stop harming Monica Sep 08 '19 at 18:23
  • If your class materials do not include explanations of basic stuff like looking at individual letters in a word and do not point to resources that you can use to learn for yourself you should, well, withdraw from that class if you can, but if that's not an option you can read the [official tutorial](https://docs.python.org/3/tutorial/introduction.html#strings) or other [resources for beginners](https://wiki.python.org/moin/BeginnersGuide/NonProgrammers). You are expected to understand the fundamentals of the language before coming here to ask questions. – Stop harming Monica Sep 08 '19 at 18:39

2 Answers2

0

You can define the inside function like this:

for translator in [eng_to_braille_1, eng_to_braille_2, eng_to_braille_3]:
    for i in word:
        print(translator[i], end=' ')
    print('\n')

The top row, middle & bottom row will be printed. But this cant be done for long string input. For that, you better find unicode for braille.

PaxPrz
  • 1,778
  • 1
  • 13
  • 29
  • But can you explain the individual lines? Reading code and understanding what it means isnt really in my skill set yet – AddoExitium Sep 08 '19 at 17:53
  • iterate all characters in word; for top row (eng_to_braille1) and print the top row. then go to next line and iterate for middle row. then move nextline & iterate through bottom row. – PaxPrz Sep 09 '19 at 03:01
0

Python dictionary is key, value storage. So if you want to find the braille value for 'a' in eng_to_braille_1 then do the following:

print(eng_to_braille_1['a'])

For a word you have to iterate over each letter in the word and find its equivalent braille value.

for c in word:
    print(eng_to_braille_1[c])
Neeraj Agarwal
  • 1,059
  • 6
  • 5