I have a dictionary where the key
is a letter in the alphabet and it’s value
is its corresponding Morse code letter (e.g. ”A”: “.-“
). I also have a user input where the user I puts there message. Once they press enter, it checks each input letter to see if it is in Morse code or an English letter by seeing if it is in the value or key. After that, I want it to then print its corresponding letter (e.g. if it found that “.-“, “A” would be printed). How would I do this?
Here is my code so far:
translation = {
"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": "--..",
" ": " "
}
user_input = input("Input english or morse code message:\n").upper()
for i in user_input:
if i in translation.keys():
print(translation.values())
if i in translation.values():
print(translation.keys())