-
Notifications
You must be signed in to change notification settings - Fork 1
/
Morse Translator Dev 1.0.py
86 lines (64 loc) · 2.05 KB
/
Morse Translator Dev 1.0.py
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import winsound
import sys
from time import sleep
morse_alph = {
'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':'--..', '0':'-----', '1':'.----', '2':'..---', '3':'...--',
'4':'....-', '5':'.....', '6':'-....', '7':'--....', '8':'---..',
'9':'----.', ' ':'/', '.':'.-.-.-', ',':'--..--'
}
def read_from_file():
print('NOTE: FILE MUST BE IN SAME DIRECTORY AS THIS PROGRAM')
filename = input('Enter the filename to read from: ').lower()
if filename[-4:] != '.txt':
filename += '.txt'
f= open(filename,'r')
user_input = f.read()
return user_input.upper()
def menu():
print('Do you want to:\n\
1) Translate from a file\n\
2) Tranlate from direct input\n\
9) quit the program')
choice = input('input')
if choice is '1':
translate_input(read_from_file())
elif choice is '2':
print('Translate directly confirmed')
elif choice is '9':
sys.exit()
else:
print('invalid choice')
def verify_input():
pass
def translate_input(user_input):
string = ''
for letter in user_input:
string += morse_alph[letter]
string += ' '
print(string)
def play_morse():
pass
def write_morse():
pass
def main():
while True:
menu()
if __name__ == '__main__':
main()
def output(string):
for char in string:
morse = morse_alph[char]
for i in morse:
if i == '.':
winsound.Beep(700,200)
elif i == '-':
winsound.Beep(700,600)
else:
sleep(0.2)
#while True:
# output(input('enter a word: ').upper())