Morse Code Encoder

The aim of this challenge is to create a Morse code converter that lets the user enter any message. The program should then display the message in Morse code. To complete this challenge you will need to know how Morse code works. If the information given below is not clear enough you can find out more about Morse code on this wikipedia page.

Morse code is a method of transmitting text information as a series of on-off tones, lights, or clicks that can be directly understood by a skilled listener or observer without special equipment.

Each character (letter or numeral) is represented by a unique sequence of dots and dashes. The duration of a dash is three times the duration of a dot.

For this challenge we will be using the international Morse code as follows:
Morse_code

Learning Objectives


By completing this challenge we are going to learn about Python dictionaries.
In Python, a dictionary consists of pairs (called items) of keys and their corresponding values.

Python dictionaries are also known as associative arrays or hash tables. The general syntax of a dictionary is as follows:
PythonDictionary

btnTryCodeOnline

Morse Code Encoder


Check the code below to encore your own message into Morse code:

Challenge #1:


Complete the code above to add the Morse code for number digits between 0 and 9 as follows:
Morse_code_numbers

Challenge #2: Morse Code Decoder


Write a program that enables you to decode a message written in Morse code. For instance, your program should be able to decode the following message:
… — … -.-. –.- -.. – .. – .- -. .. -.-. .– . .- .-. . … .. -. -.- .. -. –. ..-. .- … –

Challenge #3: Sending Light Signals


Morse_code_signalsCheck the following code used to simulate a lamp going on and off to reproduce an SOS call in Morse code: … — …

Combine this code with the code from the Morse code encoder to create light signals in Morse code. Remember the rules of Morse code:

  • Each character (letter or numeral) is represented by a unique sequence of dots and dashes.
  • The duration of a dash is three times the duration of a dot.
  • Each dot or dash is followed by a short silence, equal to the dot duration.
  • The letters of a word are separated by a space equal to three dots (one dash).
  • The words are separated by a space equal to seven dots.

Share Button
Posted in Computer Science, Python - Intermediate, Python Challenges

Our Latest Book

Follow this blog