-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
110 lines (101 loc) · 2.31 KB
/
Copy pathmain.py
File metadata and controls
110 lines (101 loc) · 2.31 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
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
""" Morse code converter and player source of lists https://www.electronics-notes.com/articles/ham_radio/morse_code/characters-table-chart.php"""
import time
import winsound as ws
f = 2500 #frequency
switcher = {
'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' : '-----',
',' : '--..--',
'?' : '..--..',
':' : '---...',
'-' : '-....-',
'"' : '.-..-.',
'(' : '-.--.',
'=' : '-...-',
'*' : '-..-',
'.' : '.-.-.-',
';' : '-.-.-.',
'/' : '-..-.',
'\'' : '.----.',
'_' : '..--.-',
')' : '-.--.-',
'+' : '.-.-',
'@' : '.--.-.',
}
def player(s):
for i in s:
print(' ',end='')
play(i)
def play(w):
w = switcher.get(w,None)
for i in w:
if i == '.':
print('.',end='')
ws.Beep(f,150)
if i == '-':
print('-',end='')
ws.Beep(f,400)
if i == ' ':
print(' ',end='')
time.sleep(0.6)
continue
time.sleep(0.5)
def converter(s,flag):
output = ''
for i in s:
if i == ' ':
output += ' '
output += ' ' + switcher.get(i,None)
print('OUTPUT - :')
print(output)
if flag:
print('playing your string...')
player(s)
print('1.) Enter string to play it : INPUT = 1 ')
print('1.) Enter string to convert it : INPUT = 2 ')
n = input()
if n == '1':
string = input('Type your String : ')
player(string)
if n == '2':
string = input('Type your string : ')
j = input('Do you want to play it too ? (y/n) : ')
if j == 'y':
converter(string,True)
if j == 'n':
converter(string,False)