forked from TheAlgorithms/Python
- Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpig_latin.py
44 lines (40 loc) · 1.01 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
35
36
37
38
39
40
41
42
43
44
defpig_latin(word: str) ->str:
"""Compute the piglatin of a given string.
https://en.wikipedia.org/wiki/Pig_Latin
Usage examples:
>>> pig_latin("pig")
'igpay'
>>> pig_latin("latin")
'atinlay'
>>> pig_latin("banana")
'ananabay'
>>> pig_latin("friends")
'iendsfray'
>>> pig_latin("smile")
'ilesmay'
>>> pig_latin("string")
'ingstray'
>>> pig_latin("eat")
'eatway'
>>> pig_latin("omelet")
'omeletway'
>>> pig_latin("are")
'areway'
>>> pig_latin(" ")
''
>>> pig_latin(None)
''
"""
ifnot (wordor"").strip():
return""
word=word.lower()
ifword[0] in"aeiou":
returnf"{word}way"
fori, charinenumerate(word): # noqa: B007
ifcharin"aeiou":
break
returnf"{word[i:]}{word[:i]}ay"
if__name__=="__main__":
print(f"{pig_latin('friends') =}")
word=input("Enter a word: ")
print(f"{pig_latin(word) =}")