Computer Science, asked by Anonymous, 9 months ago

Develop and test a Python program that allows a user to type in a message and have it converted into Morse code, and also enter a Morse code and have it converted back to the original message. The encoding of Morse code is given below.

Attachments:

Answers

Answered by Anonymous
0

Answer:

def encode(datamessage):  

   cipher = ''  

   for alphabets in datamessage:  

       if alphabets != ' ':

           cipher += MORSE_CODE_DICT[alphabets ] + ' '

       else:  

           cipher += ' '

   return cipher  

 

def decode(datamessage):  

   datamessage+= ' '

  decipher = ''  

   citext = ''  

   for alphabets in datamessage:  

    if (alphabets!= ' '):  

   i = 0

citext += l

       else:  

         i += 1

   if i == 2 :  

   decipher += ' '

           else

               decipher += list(MORSE_CODE_DICT.keys())[list(MORSE_CODE_DICT  

               .values()).index(citext)]  

               citext = ''  

  return decipher  

def main():  

   datamessage = "ITISCONVERTED"

   result = encode(datamessage.upper())  

   print (result)  

   datamessage = "--. . . -.- ... -....- ..-. --- .-. -....- --. . . -.- ... "

   result = decoede(datamessage)  

   print (result)

if __name__ == '__main__':  

   main()

Similar questions