Text to Morse Code using Python.
Run the Script:
python3 text_to_morse_code.py
Code language: CSS (css)
Source Code:
text_to_morse_code.py
#all_the symbols
symbols = {
"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": "--..",
}
#the user has to tyoe a word
ask = input("type: ")
length = len(ask)
output = ""
for i in range(length):
if ask[i] in symbols.keys():
output = output + " " + symbols.get(ask[i])
print(output)
Code language: PHP (php)