First page Back Continue Last page Overview Graphics

Solution, 2nd part

def txt2morse(txt, alphabet):

morse_code = ""

for char in txt.upper():

if char == " ":

morse_code += " "

else:

morse_code += alphabet[char] + " "

return morse_code

def morse2txt(txt, alphabet):

res = ""

for mwords in txt.split(" "):

for mchar in mwords.split():

res += alphabet[mchar]

res += " "

return res

mstring = txt2morse("So what?", char_morse)

print(mstring)

print(morse2txt(mstring, morse_char))