Morse Code Translator
From WLCS
Objectives:
- You will create a string translator that converts Morse code to a alpha-numeric characters
- You will use while loops to traverse (walk-through) a string
- You will use if-statements to check for Morse code strings
- You will use functions to retrieve corresponding alpha-numeric characters
References:
- Morse code
- Media:Strings_Python.pptx
- Strings
- Functions
- Conditionals (if-statements)
- Iteration (while loops)
Translator Guidelines:
- Dots (.), dashes (-), and spaces ( ) will be used for the code
- A single space will separate Morse code letters (e.g. "cat" = "-.-. .- -")
- Words are separated by 3 spaces (e.g. "fat cat" = "..-. .- - -.-. .- -")
Directions: Part 1: Plaintext -> Morse code
- Create a file named plain2morse.py
- Use Leet-speak Translator as a guide to create a program that converts from letters and numbers to Morse code (be sure to follow the guidelines above!)
Part 2: Morse code -> plaintext
- Create a new file named morse2plain.py
- Define a dictionary named morse2plain which will return the plaintext letter/number that corresponds to the Morse code letter
- After the dictionary, prompt the user for a Morse code string and store it in a mStr
- Create a string variable plainStr that starts with an empty string ""
- plainStr will store our translated plaintext string
- Create a string variable mLetter that starts with an empty string ""
- You will use mLetter in the loop below to store all the dots and dashes for a single Morse code letter (because a single letter can be represented with one or more dots and dashes)
- Write a loop that traverses every character of mStr
- If the current character is not a space, then add it to mLetter
- Otherwise, if the current character is a space, then translate the symbols using morse2plain[mLetter] and add the translated letter to plainStr
- After the loop, print your translated plainStr word
Additional Features:
- Add the ability to translate multiple words of Morse code to plaintext