Oct-26-2021, 03:54 PM
(Oct-26-2021, 03:16 PM)Axel_Erfurt Wrote: Is that better?
alphabet = {'a':'.-', 'b':'-...', 'c':'-.-.', 'd':'-..', 'e':'.', 'f':'..-.', 'g':'--.', 'h':'....', 'i':'..', 'j':'.---', 'k':'-.-', 'l':'.-..', 'm':'--', 'n':'-.', 'o':'---', 'p':'.--.', 'q':'--.-', 'r':'.-.', 's':'...', 't':'-', 'u':'..-', 'v':'...-', 'w':'.--', 'x':'-..-', 'y':'-.--', 'z':'--..', ' ':'', '/':'-..-.', '-':'-....-', '.':'.-.-.-', ',':'--..--', '1':'.----', '2':'..---', '3':'...--', '4':'....-', '5':'.....', '6':'-....', '7':'--...', '8':'---..', '9':'----.', '0':'-----'} morse = {} def encode(plaintext): morse_text = "" plaintext = plaintext.lower() for char in plaintext: morse_text += alphabet[char] + "/" morse_text += "//" return morse_text def decode(mroz_text): plain_text = "" morse_array = mroz_text.split("/") for val in morse_array: for key, value in alphabet.items(): if value == val: plain_text += key return plain_text print(encode("This is first testing sentence.")) print(decode(encode("This is first testing sentence."))) print(encode("ka b")) # -.-/.-//-...///
Output:-/..../../...//../...//..-./../.-./.../-//-/./.../-/../-./--.//..././-./-/./-./-.-././.-.-.-/// this is first testing sentence. -.-/.-//-...///
Yes, thank you