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!')
![64
65
66
67
68
69 while not done:
70
71
72
73 selection=input('Please make a selection: ')
74
75 ▾ if selection == "0":
76
done = True
77
78 -
79
80 morseCode=input('Please enter a word to be translated to Morse Code: ')
morseCode = morseCode.upper()
81
82
print("Morse Code for the provided letter is: ", morse_code(morseCode))
83
84 ▾ elif selection == "2":
85
86
*
done False
▶ Run
>_
morseCode=input('Please enter a word from the Morse Code Tranlator menu: ')
Ln: 92, Col: 15 (1636 selected)
hi
print (menu)
elif selection == "1":
Share Command Line Arguments
Traceback (most recent call last):
File "Untitled8.py", line 82, in <module>
print("Morse Code for the provided letter is: ", morse_code(morseCode))
File "Untitled8.py", line 56, in morse_code
return tranlation_dic[text]
KeyError: 'HI'
** Process exited - Return Code: 1 **
Press Enter to exit terminal](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F2be123e9-ab44-4f49-b994-a85643337340%2F77ca15ba-3d2b-4458-8a7e-e85268cece93%2Fsp7ksvd_processed.png&w=3840&q=75)

Required language is Python:
Code is working well, please try again. Error is resolved.
Step by step
Solved in 3 steps with 4 images









