forked from mcewand/Morse-Code-Translator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtranslator.py
55 lines (52 loc) · 939 Bytes
/
translator.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
#!/usr/bin/python
# -*- coding: utf-8 -*-
#convert a string of input text to morse code
import serial
#morse code array
morseDict = {
'a':'13',
'b':'3111',
'c':'3131',
'd':'311',
'e':'1',
'f':'1131',
'g':'331',
'h':'1111',
'i':'11',
'j':'1333',
'k':'313',
'l':'1311',
'm':'33',
'n':'31',
'o':'333',
'p':'1331',
'q':'3313',
'r':'131',
's':'111',
't':'3',
'u':'113',
'v':'1113',
'w':'133',
'x':'3113',
'y':'3133',
'z':'3311',
' ':'00000',
}
text = raw_input('Please enter your string:\n')
text_div = list(text)
for item in text_div:
if (item == ' '):
item = '0'
#print text_div
morse_list = list()
for char in text:
for key in morseDict:
if (char.lower() == key):
value = morseDict[key]
morse_list.append(value)
#print morse_list
morse_out = '0'
for item in morse_list:
morse_out = morse_out + item + '0'
print 'Your text string in Morse Code is: \n'
print morse_out