Pig Latin Translator不会发表任何言论

时间:2016-11-01 19:16:04

标签: python python-2.7

嗨,我需要为一堂课完成一个工作的Pig Latin翻译。译者应该接受一个单词,如果它以元音开头,在结尾添加“ay”,如果以辅音开头,则将辅音带到后面,然后添加“ay”,它应该继续向后移动直到它击中元音。例如,“树”这个词应该成为“eetray”。我不确定在代码中我哪里出错了,但是当我运行它时它不会给我任何东西所以如果我放入“树”它只会重新启动代码并再次询问一个单词。欢迎任何帮助。谢谢!

vowels = "AEIOU" 
realLetters = "abcdefghijklmnopqrstuvwxyz"
while true:
     isRealWord = True
 word = raw_input ("Please tell me a word to translate: ").lower()
 for letter in range(len(word)):
     if word[letter] in realLetters:
         continue
     else:
         print "That is not a real word. Just leave."
         isRealWord = False

 if isRealWord == True:
    firstLetter = word[0]
    secondLetter = word[1]
    thirdLetter = word[2]

    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[0] in vowels:
        print pigWord0.lower()
    elif pigWord1[0] in vowels:
        print pigWord1.lower()
    elif pigWord2[0] in vowels:
        print pigWord2.lower()
    elif pigWord3[0] in vowels:
        print pigWord3.lower()

1 个答案:

答案 0 :(得分:0)

我怀疑缩进/语法错误是SO和/或延迟复制的问题,因为我可以使用固定代码复制您的失败示例:

除了vowels列表之外,所有内容都被小写比较,这是全部大写。它必须是aeiouA!= a,其他所有内容都是小写的。

您仍需要修复语法,但这解决了问题。