forked from covcom/122COM_algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lab_morse.py
48 lines (38 loc) · 1.21 KB
/
lab_morse.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
import sys
import calendar
class Morseifier:
# MAKE AS MANY CHANGES TO THE CLASS AS YOU WANT
def translate(self,text):
# COMPLETE ME
return
def untranslate(self,morse):
# COMPLETE ME
return
def main():
m = Morseifier()
tests = [('MORSE CODE','-- --- .-. ... . / -.-. --- -.. .'),
('INSPECTOR MORSE','.. -. ... .--. . -.-. - --- .-. / -- --- .-. ... .'), \
('',''), \
('LAST OF THE MORSICANS','.-.. .- ... - / --- ..-. / - .... . / -- --- .-. ... .. -.-. .- -. ...')]
errors = 0
for text, morse in tests:
yourMorse = m.translate(text)
yourText = m.untranslate(morse)
if yourMorse != morse:
print('Error! translating %s' % text)
print('Yours : "%s"' % yourMorse)
print('Correct: "%s"' % morse)
errors += 1
if yourText != text:
print('Error! untranslating %s' % morse)
print('Yours : "%s"' % yourText)
print('Correct: "%s"' % text)
errors += 1
if errors == 0:
print('Congratulations, no errors')
print('-.-. --- -. --. .-. .- - ..- .-.. .- - .. --- -. ... / -. --- / . .-. .-. --- .-. ...')
else:
print('Uh oh, %d error/s remain' % errors)
print('..- .... / --- .... / . .-. .-. --- .-. ... / .-. . -- .- .. -.')
if __name__ == '__main__':
sys.exit(main())