First page Back Continue Last page Overview Image

Lösung, 2. Teil

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 = ""

mwords = txt.split(" ")

for mword in mwords:

for mchar in mword.split():

res += alphabet[mchar]

res += " "

return res

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

print(mstring)

print(morse2txt(mstring, morse_char))