-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMorse-Code_Machine.py
More file actions
39 lines (34 loc) · 1.52 KB
/
Morse-Code_Machine.py
File metadata and controls
39 lines (34 loc) · 1.52 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
# Translate letters in an input string to morse code
MORSE_CODE_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':'-----', ',':'--..--', '.':'.-.-.-',
'?':'..--..', '/':'-..-.', '-':'-....-',
'(':'-.--.', ')':'-.--.-'}
shouldContinue = True
def encrypt():
coded_message = ''
for char in message_to_encrypt:
if char != ' ':
coded_char = MORSE_CODE_DICT[char]
coded_message += coded_char
else:
coded_message += ' '
print(f'Here\'s your Morse code: {coded_message}')
while shouldContinue:
print("Hello! Welcome to my Morse code machine:)")
message_to_encrypt = input('What would you like to encrypt into morse code? ').upper()
encrypt()
play_again = input("Would you like to use the machine again? y/n ").lower()
if play_again == 'n':
print("Thanks for trying the program!")
shouldContinue = False