-
Notifications
You must be signed in to change notification settings - Fork 0
/
logic.py
59 lines (39 loc) · 1.4 KB
/
logic.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
56
from os import system
MORSE = '".-"-..."-.-."-.."."..-."--."...."..".---"-.-".-.."--"-."---' \
'".--."--.-".-."..."-"..-"...-".--"-..-"-.--"--.."' \
'..--"-.-.--"..--..".-.-.-"--..--'
MORSECHAR = MORSE.split('"')
ROMANIC = '~"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' \
'" "!"?".",'
ROMANICCHAR = ROMANIC.split('"')
def romanify(txt):
res = str()
letters = txt.split(' ')
for index, morse_letter in enumerate(letters): # Search for every typed letter
# Check the letter's positions.
for position, searched_letter in enumerate(MORSECHAR):
if morse_letter == searched_letter:
res += ROMANICCHAR[position]
return res
def morsefy(txt):
res = str()
for letter in txt:
index = ROMANICCHAR.index(letter)
res += MORSECHAR[index] + ' '
return res
def title():
print(f'{"MORSE":^50}\n'
f'{"&":^50}\n'
f'{"ROMANIC":^50}\n'
f'{"=" * 50}\n'
f'Type "$help" for help')
def functions(cmd):
if cmd.lower() == '$help':
print(f'You can type in using romanic letters or morse code. If you type in romanic, it will translate\n'
f'to morse code and vice versa.\n'
f'\n'
f'{"FUNCTIONS":^30}\n'
f'CLEAR: {"_" * 16} $clear')
if cmd.lower() == '$clear':
system('clear')
title()