Hi I need to complete a working Pig Latin translator for a class. The translator is supposed to take a word and if it begins with a vowel add "ay" at the end and if it begins with a consonant take the consonant to the back and then add "ay" it should keep moving back until it hits a vowel. For example the word ¨tree¨ should become "eetray". I´m not sure where in the code I when wrong, but when I run the could it doesn't give me anything so if I put in "tree" it will just restart the code and ask for a word again. Any help would be welcome. Thanks!
vowels = "AEIOU"
realLetters = "abcdefghijklmnopqrstuvwxyz"
isRealWord = True
word = raw_input ("Please tell me a word to translate: ").lower()
for letter in range(len(word)):
if word[letter] in realLetters:
print "That is not a real word. Just leave."
isRealWord = False
if isRealWord == True:
firstLetter = word
secondLetter = word
thirdLetter = word
pigWord0 = word + "ay"
TheRestOfTheWord = word[1:]
pigWord1 = TheRestOfTheWord + firstLetter + "ay"
TheRestOfTheWord = word[2:]
pigWord2 = TheRestOfTheWord + firstLetter + secondLetter + "ay"
TheRestOfTheWord = word[3:]
pigWord3 = TheRestOfTheWord + firstLetter + secondLetter + thirdLetter + "ay"
if pigWord0 in vowels:
elif pigWord1 in vowels:
elif pigWord2 in vowels:
elif pigWord3 in vowels:
I suspect the indentation/syntax errors are issues with SO and/or lazy copying, as I can replicate your failure example with fixed code:
Everything is compared lowercase except the
vowels list, which is in all caps. it needs to be
a and everything else is lowercase.
You still have to fix your syntax, but this solves the question as asked.