Hint
🧠Not sure where to start?
Start by creating a dictionary that maps each letter and number to its Morse code symbol. For example:
morse_dict = {
'A': '.-', 'B': '-...', 'C': '-.-.', # and so on
}
Then, ask the user to enter a message:
text = input("Enter text to convert to Morse code: ")
Convert the text to uppercase so it matches the keys in your dictionary:
text = text.upper()
Now think: how can you go through each character and find its Morse code equivalent? Try using a for
loop:
for char in text:
if char in morse_dict:
# add the Morse code to your result string
Separate each Morse character with a space, and use /
to separate words (spaces in the input).