Python Forum

Full Version: Pig Latin
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi, I am trying to make a pig latin function in Python, which takes in a word and returns its pig latin translation. You can convert an English word into Pig Latin by moving all the consonants up to the first vowel to the end of the word and then appending "ay", e.g 'hello' becomes 'ellohay'.
This is my code:

def pig_latin(word):
""" Returns the pig latin translation of a word. """
i=0
new_word = word
vowel = ["a", "e","i","o","u"]
while word not in vowel:
word[i] = consonant
new_word = new_word[(i+1):] + consonant
i+=1
final_word = new_word + "ay"
return final_word

When I run it, it gives: NameError: name 'consonant' is not defined
I would really appreciate help regarding this.

Thank you!
[/i]
What else would you expect? You never defined it anywhere. Maybe you meant to swap the sides of the assignment?

Also, in the future please make sure to always use code tags on code; as you can see here, the indentation is lost, and it's essential to understanding anything other than the move trivial code.