Question
Write a Morse Code decoder in python 3 I tried the following, but did not match the expected result morse_code_dict = { 'A':'.-', 'B':'-...', 'C':'-.-.',
Write a Morse Code decoder in python 3
I tried the following, but did not match the expected result
morse_code_dict = { 'A':'.-', 'B':'-...', 'C':'-.-.', 'D':'-..', 'E':'.', 'F':'..-.', 'G':'--.', 'H':'....', 'I':'..', 'J':'.---', 'K':'-.-', 'L':'.-..', 'M':'--', 'N':'-.', 'O':'---', 'P':'.--.', 'Q':'--.-', 'R':'.-.', 'S':'...', 'T':'-', 'U':'..-', 'V':'...-', 'W':'.--', 'X':'-..-', 'Y':'-.--', 'Z':'--..', '1':'.----', '2':'..---', '3':'...--', '4':'....-', '5':'.....', '6':'-....', '7':'--...', '8':'---..', '9':'----.', '0':'-----', ', ':'--..--', '.':'.-.-.-', '?':'..--..', '/':'-..-.', '-':'-....-', '(':'-.--.', ')':'-.--.-'}
#def encrypt(message): # cipher = '' # for letter in message: # if letter != ' ': # cipher += morse_code_dict[letter]+' ' # else: # cipher += ' ' # return cipher
def decrypt(message): message += ' ' decipher = '' mycitext = '' for letter in message: if (letter != ' '): i = 0 mycitext += letter else: i += 1 if i == 2 : decipher += ' ' else: decipher += list(morse_code_dict.keys())[list(morse_code_dict.values()).index(mycitext)] mycitext = '' return decipher
Morse Code Programming challenge description: You have received a text encoded with Morse code and want to decode it. Input: Your program should read lines from standard input. Each line contains a Morse code message. Each letter in the code is separated by a space char, each word is separated by 2 space chars. The input will contain encoded letters and numbers only. Output: Print out the decoded words. Test 1 Test Input Expected Output AVZWHIECX 45 Test 2 Test Input Expected Output BH3Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started