-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmorsey.py
More file actions
38 lines (31 loc) · 1.27 KB
/
morsey.py
File metadata and controls
38 lines (31 loc) · 1.27 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
code = {'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': '----.', ' ': '/'
}
decode = dict((v, k) for (k,v) in code.items())
def translate(morsecode):
output = []
splittext = morsecode.split()
for morsel in splittext:
output.append(decode[morsel])
readout = ''.join(output)
print readout
def morsify(englesh):
codeout = []
listing = list(englesh)
for letter in listing:
codeout.append(code[letter])
morsecule = ' '.join(codeout)
print morsecule
translate(".... . .-.. .-.. --- / .--. ..- -. .. - .- / - .... .. ... / .. ... / -- --- .-. ... . / -.-. --- -.. . / ..-. --- .-. / .... . .-.. .-.. --- / .--. ..- -. .. - .-")
morsify("HELLO PUNITA THIS IS MORSE CODE FOR HELLO PUNITA")