generated from profe-kevs/python-3-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpig_latin.py
34 lines (24 loc) · 1.1 KB
/
pig_latin.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
def is_consonant(ch):
if ch in "aeiou":
return False
else :
return True
def first_condition(first_two_ch):
return not is_consonant(first_two_ch[0]) or (first_two_ch == "xr" or first_two_ch == "yt")
def translate(text):
text_lower = text.lower()
if(first_condition(text_lower[:2])):
return text_lower + "ay"
y_partition = text_lower.partition("y")
qu_partition = text_lower.partition("qu")
if is_consonant(text_lower[1]) and not text_lower[1] == "y" and not text_lower[1] == "u" and not text_lower[1] == "u":
return text_lower[2:] + text_lower[:2] + "ay"
if not (y_partition[0] == text_lower):
if y_partition[0] == '':
return "".join(y_partition[1:]) + y_partition[1] + "ay"
return "".join(y_partition[1:]) + y_partition[0] + "ay"
if not (qu_partition[0] == text_lower):
if qu_partition[0] == '':
return "".join(qu_partition[2:]) + qu_partition[1] + "ay"
return "".join(qu_partition[2:]) + "".join(qu_partition[:2]) + "ay"
return text_lower[1:] + text_lower[:1] + "ay"