-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
49 lines (38 loc) · 1.56 KB
/
Copy pathmain.py
File metadata and controls
49 lines (38 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
text_to_morse_dict = {
'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_to_text_dict = {value: key for key, value in text_to_morse_dict.items()}
def text_to_morse():
text = input('Text: ').lower()
morse_list = [text_to_morse_dict[t] for t in text]
print(f'Morse: {" ".join(morse_list)}')
def morse_to_text():
morse = input('Morse: ').lower().split()
text_list = [morse_to_text_dict[word] for word in morse]
text = ''
for letter in text_list:
text += letter
print(text)
project_start = True
while project_start:
user_choice = input('''
Welcome to text-morse converter.
press m to text -> morse
press t to morse -> text
press any other key to quit
answer:''')
if user_choice.lower() == 'm':
text_to_morse()
elif user_choice.lower() == 't':
morse_to_text()
else:
project_start = False