-
Notifications
You must be signed in to change notification settings - Fork 0
/
translate.py
52 lines (45 loc) · 1.63 KB
/
translate.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
# It is funny program that can translate english to japanese (actually it is not japanes LOL)
def from_eng_to_jap(txt):
japnese = {
'A': "ka", 'B': "tu", "C": "mi", 'D': 'te', 'E': 'ku', 'F': 'lu', 'G': 'ji',
'H': 'ri', 'I': 'ki', 'J': 'zu', 'K': 'me', 'L': 'ta', 'M': 'rn', 'N': 'to',
'O': 'mo', 'P': 'no', 'Q': 'ke', 'R': 'shi', 'S': 'ar', 'T': 'chi', 'U': 'do',
'V': 'ru', 'W': 'ei', 'X': 'na', 'Y': 'fu', 'Z': 'zi'
}
translated = ''
for ch in txt:
translated += japnese.get(ch.upper(), ch).lower()
return translated
def from_jap_to_eng(txt):
english = {
"ka": 'A', "tu": "B", "mi": "C", 'te': 'D', 'ku': 'E', 'lu': 'F', 'ji': 'G',
'ri': 'H', 'ki': 'I', 'zu': 'J', 'me': 'K', 'ta': 'L', 'rn': 'M', 'to': 'N',
'mo': 'O', 'no': 'P', 'ke': 'Q', 'shi': 'R', 'ar': 'S', 'chi': 'T', 'do': 'U',
'ru': 'V', 'ei': 'W', 'na': 'X', 'fu': 'Y', 'zi': 'Z'
}
translated = ""
i = 0
while i < len(txt)-1:
if txt[i:i+2] in english:
translated += english[txt[i:i+2]]
i += 2
continue
if txt[i:i+3] in english:
translated += english[txt[i:i+3]]
i += 3
continue
else:
translated += txt[i]
i += 1
return translated
if __name__ == "__main__":
prompt = """
1.To translate from English to Japanese
2.To translate form Japanese to English
Choice: """
choice = int(input(prompt))
txt = input("Enter Text to translate: ")
if choice == 1:
print(from_eng_to_jap(txt))
elif choice == 2:
print(from_jap_to_eng(txt).lower())