-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmorse coad.py
36 lines (36 loc) · 1.2 KB
/
morse coad.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
morse_code=['.-','-...','-.-.','-..','.','..-.','--.',
'....','..','.---','-.-','.-..','--','-.',
'---','.--.','--.-','.-.','...','-','..-',
'...-','.--','-..-','-.--','--..','.----',
'..---','...--','....-','.....','-....',
'--...','---..','----.','-----','/']
alnum=list("abcdefghijklmnopqrstuvwxyz1234567890 ")
while True:
start=input("to continue press enter\n\t[to close press #]")
if start!= '':
print("\n unvalied syntex \t try again\n")
continue
else:break
while True:
words=[]
data=list(input("enter to code or decord :\n\t\t\t"))
for i in data:
if i in alnum:
words.append(i)
else:pass
if data[0] in alnum:
for i in words :
print(morse_code[alnum.index(i)],end=' ')
if data[0]in ['.','-']:
code,data='',data
if data[-1]!=" ":
data.append(" ")
for i in data:
if i==' ':
print(alnum[morse_code.index(code)],end='')
code=''
else: code+=i
if data[0]=='#':
print("\n\t\t\t\t\tthanks for using")
break
print()