Morse Code Translator

From WLCS
Jump to: navigation, search

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:

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

  1. Create a file named plain2morse.py
  2. 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

  1. Create a new file named morse2plain.py
  2. Define a dictionary named morse2plain which will return the plaintext letter/number that corresponds to the Morse code letter
  3. After the dictionary, prompt the user for a Morse code string and store it in a mStr
  4. Create a string variable plainStr that starts with an empty string ""
    • plainStr will store our translated plaintext string
  5. 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)
  6. Write a loop that traverses every character of mStr
    1. If the current character is not a space, then add it to mLetter
    2. Otherwise, if the current character is a space, then translate the symbols using morse2plain[mLetter], add the translated letter to plainStr, and reset mLetter
  7. After the loop, print your translated plainStr word

Additional Features:

  • Add the ability to translate multiple words of Morse code to plaintext