Warning! It seems that you are using Dodona within another webpage, so not everything may work properly. Let your teacher know so that he can solve the problem by adjusting a setting in the learning environment. In the meantime, you can click this link to open Dodona in a new window.
Warning! The page was not fully loaded, probably because of a network issue. It could be that not all functionalities work as expected. Please try reloading the page.
# Morse code program
# -------------------------
# Subprograms
# -------------------------
def translate(morse):
match morse:
case ".-":
return "A"
case "-...":
return "B"
case "-.-.":
return "C"
case "-..":
return "D"
case ".":
return "E"
case "..-.":
return "F"
case "--.":
return "G"
case "....":
return "H"
case "..":
return "I"
case ".---":
return "J"
case "-.-":
return "K"
case ".-..":
return "L"
case "--":
return "M"
case "-.":
return "N"
case "---":
return "O"
case ".--.":
return "P"
case "--.-":
return "Q"
case ".-.":
return "R"
case "...":
return "S"
case "-":
return "T"
case "..-":
return "U"
case "...-":
return "V"
case ".--":
return "W"
case "-..-":
return "X"
case "-.--":
return "Y"
case "--..":
return "Z"
case _:
return " "
def read_morse(filename):
# -------------------------
# Main program
# -------------------------
message = read_morse("message.txt")
print(message)
Python sandbox
This window allows you to run Python code without installing a thing. The code you write here is not automatically submitted to Dodona.