### # piglatin.py # # author: Kristina Striegnitz # # version: 1/27/2009 # ### def eng_to_pig(eng_word): """ Takes one English word as argument, translates it into Pig-latin and returns the result. """ if len(eng_word) == 0: pig_word = eng_word # word starts with a vowel elif eng_word[0] in "aeiou": pig_word = eng_word + "way" # word starts with a consonant followed by a vowel elif eng_word[1] in "aeiou": pig_word = eng_word[1:] + eng_word[0] + "ay" # word starts with two consonants followed by a vowel elif eng_word[2] in "aeiou": pig_word = eng_word[2:] + eng_word[0] + eng_word[1] + "ay" # word starts with three consonants (or more, but only three are moved to the end) else: pig_word = eng_word[3:] + eng_word[0] + eng_word[1] + eng_word[2] + "ay" return pig_word ## To test: print "pig -> " + eng_to_pig("pig") print "star -> " + eng_to_pig("star") print "spray -> " + eng_to_pig("spray") print "eagle -> " + eng_to_pig("eagle")