-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpiglatin_2.py
More file actions
28 lines (23 loc) · 1004 Bytes
/
piglatin_2.py
File metadata and controls
28 lines (23 loc) · 1004 Bytes
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
def pigLatin (string1):
words=string1.split() # Split word array into letters
l_words=string1.lower().split() # Make everything lowecase
pig_latin=[] # Make new empty array for pig latin transaltion
for word in l_words:
if word[0] in 'aeiou': # Search array for letters AEIOU
pig_latin.append(word+'way') # Add WAY if found
else:
vowel_pos=0 # Counter
for w in word: # Go though array
if w in 'aeiou': # If vlaue matches
vowel_pos=word.index(w) #Write index position
break
else:
pass
pig_latin.append(word[vowel_pos:]+word[:vowel_pos]+'ay') #Convert word to piglatin
for i in range (0,len(words)-1):
if words[i].istitle():
pig_latin[i]=pig_latin[i].title()
print("Pig Latin Version is: "+" ".join(pig_latin))
pigLatin("shark")
pigLatin("Ant")
pigLatin("Cat")