1
+ import pyperclip
2
+ # Required constants
3
+ normal_word = ["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" ,
4
+ "0" ,"1" ,"2" ,"3" ,"4" ,"5" ,"6" ,"7" ,"8" ,"9" ]
5
+
6
+ morse_code = [".-" ,"-..." ,"-.-." ,"-.." ,"." ,"..-." ,"--." ,"...." ,".." ,".---" ,"-.-" ,".-.." ,"--" ,"-." ,"---" ,".--." ,"--.-" ,".-." ,"..." ,"-" ,"..-" ,"...-" ,".--" ,"-..-" ,"-.--" ,"--.." ,
7
+ "-----" ,".----" ,"..---" ,"...--" ,"....-" ,"....." ,"-...." ,"--..." ,"---.." ,"----." ]
8
+ def option_menu ():
9
+ option = int (input ("Choose 1.For Encoding and 2.For Decoding:" ))
10
+ if (option == 1 ):
11
+ word = input ("Enter the sentence that you want to encode:" ).upper ()
12
+ coded_form = ""
13
+ for letter in word :
14
+ if letter == " " :
15
+ coded_form += "/ "
16
+ else :
17
+ ind = normal_word .index (letter )
18
+ coded_form += morse_code [ind ]
19
+ coded_form += " "
20
+ print (f"{ word } in morse code is { coded_form } " )
21
+ pyperclip .copy (coded_form )
22
+ print ("Copied it to clipboard 😉" )
23
+ print ("\n " )
24
+ option_menu ()
25
+
26
+ if (option == 2 ):
27
+ decoded_form = ""
28
+ encode_word = input ("Enter the sentence that you want to decode:" )
29
+ encoded_word = encode_word .split (" " )
30
+ for item in encoded_word :
31
+ if item .isalnum () or item .isalpha ():
32
+ print ("Please enter valid morse code 😀" )
33
+ option_menu ()
34
+ if item == "/" :
35
+ decoded_form += " "
36
+ continue
37
+ if item == "" :
38
+ continue
39
+ else :
40
+ ind = morse_code .index (item )
41
+ decoded_form += normal_word [ind ]
42
+ print (f"{ encode_word } in decoded form is { decoded_form } " )
43
+ pyperclip .copy (decoded_form )
44
+ print ("Copied it to clipboard 😉" )
45
+ print ("\n " )
46
+ option_menu ()
47
+
48
+
49
+
50
+ option_menu ()
0 commit comments