Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

PYTHON - Write a function named to_morse_code that converts strings into their M

ID: 3719873 • Letter: P

Question

PYTHON -

Write a function named to_morse_code that converts strings into their Morse code equivalents. Morse code is a mapping from each character from A-Z to a sequence of dots and dashes. For example, the string "SOS" could be represented in Morse code as '... -= 1- ...'.

Your function accepts two parameters: a dictionary from one-letter strings to strings representing their Morse encodings, and a String of text to convert. Assume that the provided client code builds a dictionary from individual text characters to their Morse code equivalents. For example, the key 'A' maps to ".-". Your function accepts such a map, and a string to be converted, and should prout the Morse code equivalent of the given string to the console.

For example, if the letter to Morse code map is stored in a variable called mapping, the call of to_morse_code(mapping, "SOS TITANIC") should print the following console output:

Note that the string might contain some characters that are not A-Z letters (like spaces) just skip those characters. You may assume that the mapping passed contains a mapping for every letter from A-Z in uppercase. Do not modify the letter map that is passed in.

Explanation / Answer

def _morse_cose(Morse,s1): ''' :param Morse: dictionary which maps alphabets to morse code :param s1: string to be morse coded :return: coded:string coded in morse ''' coded='' for i in s1: if i in Morse: coded+=Morse[i] else: coded+=i return coded