Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Morse Encoder by Pavellver
MORSE = {
"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": "--..",
"0": "-----",
"1": ".----",
"2": "..---",
"3": "...--",
"4": "....-",
"5": ".....",
"6": "-....",
"7": "--...",
"8": "---..",
"9": "----.",
}
def morse_encoder(text: str) -> str:
code = ''
for i in text.lower():
if i == ' ':
code += ' '
else:
code += MORSE[i] + ' '
return code.strip()
print("Example:")
print(morse_encoder("some text"))
assert morse_encoder("some text") == "... --- -- . - . -..- -"
assert (
morse_encoder("I was born in 1990")
== ".. .-- .- ... -... --- .-. -. .. -. .---- ----. ----. -----"
)
print("The mission is done! Click 'Check Solution' to earn rewards!")
March 3, 2023
Comments: