# CPSC 115 
# In class example
# Converts words into their pig latin versions


def findFirstVowel(word):
	'''Returns the first vowel in word or -1 if no vowels'''
	i = 0
	while i < len(word):
		if word[i] == 'a' or word[i] == 'e' or word[i] =='i' or word[i] == 'o' or word[i] == 'u':
			return i
		i = i + 1
	return -1

#print findFirstVowel('bring')
#print findFirstVowel('any')
#print findFirstVowel('zbgny')

def pigLatin(word):
	'''Converts word to Pig Latin and returns the result'''
	pigword = ""
	word = word.lower()
	firstvowel = findFirstVowel(word)
	if firstvowel == 0:   # word begins with a vowel
		pigword = word + 'yay'
	else:
		pigword = word[firstvowel:] +  word[0:firstvowel] + 'ay'
	return pigword

#print 'Pig latin of bring = ', pigLatin('bring')
#print pigLatin('any')
#print pigLatin('alpha')
#print pigLatin('zbgny')
#print pigLatin('string')

# Removes all punctuation and white space 
def clean(word):
	i = 0
	anotherword = ''
	while i < len(word):
		if word[i].isalpha():
			anotherword = anotherword + word[i]
		i = i + 1
	return anotherword

#f = open("poem.txt")
#print f.readline()

# Returns the Pig latin translation
def toPigLatin(sentence):
	newsentence = ''
	x = 0
	y = sentence.find(' ', x)
	while y != -1:
		word = sentence[x:y]
		newsentence = newsentence + pigLatin(clean(word)) + ' '
		#print pigLatin(clean(word))
		x = y + 1
		y = sentence.find(' ', x)
	return newsentence


f = open("poem.txt")
for line in f:
	sentence = line.strip() + ' '
	#print pigLatin(sentence)
	print toPigLatin(sentence)
	
		

