All solutions are to be written using Python 3. Make sure you provide comments i
ID: 3669607 • Letter: A
Question
All solutions are to be written using Python 3. Make sure you provide comments including the file name, your name, and the date at the top of the file you submit.Create a function called morseCode which expects no parameters. This function will get its input entirely from the keyboard. The purpose of the function is to translate strings of text composed of the 26 letters of the English alphabet into International Morse Code and print the resulting string. Here is a sample of what the dialogue between your function and the user should look like:Enter sentence to be translated (*** to end): i wish i had a pony Morse code:... -................- -..Enter sentence to be translated (*** to end): the quick brown fox jumped over the lazy dog Morse code: -..... -.-..-.. -.-. -.- -... ------. - Enter sentence to be translated (*** to end): will this work? Morse code:. -... -... -.. -.......... ----. -. -. - ### Enter sentence to be translated (*** to end): Morse code: Enter sentence to be translated (*** to end): *** Program has ended As in the examples above, the printed output should have exactly one space between the Morse code patterns within a single word (i.e., "the" becomes.....") and exactly three spaces between words (i.e., "the lazy" becomes "-..........---.. -. - ").You may assume that the text entered at the keyboard will include only the 26 lower case letters of the English alphabet. If something other than one of those 26 letters is entered, your function should translate the unexpected character into "###" as shown in the third example above. Your function should print, not return, answers.The key for converting English letters to Morse code is given in the following list of lists. Use this list of lists in your program. While Python's dictionary feature might be a better choice for this problem, you'll appreciate the practice with lists of lists.Explanation / Answer
CODE = {'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': '--..',
'0': '-----', '1': '.----', '2': '..---',
'3': '...--', '4': '....-', '5': '.....',
'6': '-....', '7': '--...', '8': '---..',
'9': '----.'
}
CODE_REVERSED = {value:key for key,value in CODE.items()}
def to_morse(s):
return ' '.join(CODE.get(i.upper()) for i in s)
msg=raw_input("Enter the sentense to be translated without spaces");
print to_morse(msg)