Question

Write a function that takes a sentence as a parameter and translates it into a Morse...

Write a function that takes a sentence as a parameter and translates it into a Morse code message in Python. The Morse coded message should be displayed at the console in one continuous line, each Morse code sequence should be delimited by space.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Z- , Q:: DICT = { A:.-, C:-.., D:-.., E: F:..., G:.-., H: I:.., ij:.---,K: M:. O

Code for copying

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':'-----', ', ':'--..--', '.':'.-.-.-',
                    '?':'..--..', '/':'-..-.', '-':'-....-',
                    '(':'-.--.', ')':'-.--.-'}
string=str(input("Enter the sentence : "))
encrypted=''
j=string.upper()
for i in j:
    if i != ' ':
        encrypted+=DICT[i]+' '
    else:
        encrypted+=' '
print(encrypted)       

Add a comment
Know the answer?
Add Answer to:
Write a function that takes a sentence as a parameter and translates it into a Morse...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT