Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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 BH3

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David M. Kroenke, David J. Auer

7th edition

133544621, 133544626, 0-13-354462-1, 978-0133544626

More Books

Students also viewed these Databases questions

Question

Why do teenagers and young people have high unemployment rates?

Answered: 1 week ago