Lesson 24: Morse code

posted May 4, 2018, 7:59 AM by Attila Lengyel
import morsedict as m

print(m.morsetab["S"] + m.morsetab["O"] + m.morsetab["S"])

text = input("Give me some text:")
morsecode = ""
for c in text:
  morsecode += m.morsetab[c] + " "
print(morsecode)

morsetab2 = {}
for k,v in m.morsetab.items():
  morsetab2[v] = k
 
text2 = input("Give me a morse code:")
morsecode2 = ""
morsecodeline = ""
for c in text2:
  if c != " ":
    morsecode2 += c
  else:
    morsecodeline += morsetab2[morsecode2]
    morsecode2 = ""

print(morsecodeline)
Comments