ERROR IN PYTHON CODE. SCREEN SHOT ATTACHED def morse_code(text): tranlation_dic = { "A": ".-", "B": "-...", "C": "-.-.", "D": "-..", "E": ".", "F": "..-.", "G": "--.", "H": "....", "I": "..", "J": ".---", "K": "-.-", "L": ".-..", "M": "--", "N": "-.", "O": "---", "P": ".--.", "Q": "--.-", "R": ".-.", "S": "...", "T": "-", "U": "..-", "V": "...-", "W": ".--", "X": "-..-", "Y": "-.--", "Z": "--..", ".-": "A", "-...": "B", "-.-.": "C", "-..": "D", ".": "E", "..-.": "F", "--.": "G", "....": "H", "..": "I", ".---": "J", "-.-": "K", ".-..": "L", "--": "M", "-.": "N", "---": "O", ".--.": "P", "--.-": "Q", ".-.": "R", "...": "S", "-": "T", "..-": "U", "...-": "V", ".--": "W", "-..-": "X", "-.--": "Y", "--..": "Z" } menu = """ Morse Code Translator 0: Exit 1: Translate a word into Morse Code 2: Translate Morse Code to text. """ done = False while not done: print(menu) selection = input('Please make a selection: ') if selection == "0": done = True elif selection == "1": morseCode = input('Please enter a word to be translated to Morse Code: ') morseCode = morseCode.upper() print('Morse Code for the provided letter is: ', morse_code(morseCode)) elif selection == "2": morseCode = input('Please enter a word from the Morse Code Tranlator menu: ') print('Text for the provided Morse Code is: ', morse_code(morseCode)) else: print('Selection is invalid. Only 0, 1, and 2 are the acceptable inputs.') print('Done!')
ERROR IN PYTHON CODE. SCREEN SHOT ATTACHED
def morse_code(text):
tranlation_dic = {
"A": ".-",
"B": "-...",
"C": "-.-.",
"D": "-..",
"E": ".",
"F": "..-.",
"G": "--.",
"H": "....",
"I": "..",
"J": ".---",
"K": "-.-",
"L": ".-..",
"M": "--",
"N": "-.",
"O": "---",
"P": ".--.",
"Q": "--.-",
"R": ".-.",
"S": "...",
"T": "-",
"U": "..-",
"V": "...-",
"W": ".--",
"X": "-..-",
"Y": "-.--",
"Z": "--..",
".-": "A",
"-...": "B",
"-.-.": "C",
"-..": "D",
".": "E",
"..-.": "F",
"--.": "G",
"....": "H",
"..": "I",
".---": "J",
"-.-": "K",
".-..": "L",
"--": "M",
"-.": "N",
"---": "O",
".--.": "P",
"--.-": "Q",
".-.": "R",
"...": "S",
"-": "T",
"..-": "U",
"...-": "V",
".--": "W",
"-..-": "X",
"-.--": "Y",
"--..": "Z"
}
menu = """
Morse Code Translator
0: Exit
1: Translate a word into Morse Code
2: Translate Morse Code to text.
"""
done = False
while not done:
print(menu)
selection = input('Please make a selection: ')
if selection == "0":
done = True
elif selection == "1":
morseCode = input('Please enter a word to be translated to Morse Code: ')
morseCode = morseCode.upper()
print('Morse Code for the provided letter is: ', morse_code(morseCode))
elif selection == "2":
morseCode = input('Please enter a word from the Morse Code Tranlator menu: ')
print('Text for the provided Morse Code is: ', morse_code(morseCode))
else:
print('Selection is invalid. Only 0, 1, and 2 are the acceptable inputs.')
print('Done!')
Required language is Python:
Code is working well, please try again. Error is resolved.
Step by step
Solved in 3 steps with 4 images