2015-07-02 60 views
0

我试图添加一个条件,如果while循环遇到一个“Y”或“Y”它仍然将字母移动到最后,但保持“Y”或“Y”在开始的时候,但循环将结束,只要加入“AY”虽然循环多个条件不起作用

print("Pig Latin Translator Test!") 
name = raw_input("What is your name, friend?") 
if len(name) > 0 and name.isalpha(): 
    print("Hello!") 
else: 
    print("That's not a name!") 
word = raw_input("What is your word?") 
VOWELS = ("a", "e", "i", "o", "u", "A", "E", "I", "O", "U") 
YList = ("Y", "y") 
if word[0] in VOWELS: 
    word = word + "yay" 
else: 

这是导致问题的部分:

while word[0] in YList or (not VOWELS): 
     word = word[1:] + word[0] 
    word = word + "ay" 
print (word) 
+0

的可能重复[蟒蛇的Pig Latin转换器(http://stackoverflow.com/questions/15400008/python-pig-latin-converter) – fferri

+0

你为什么使用元音的大写和小写字符,而不是使用'.upper()'和'.lower()'函数? –

+0

这是一个猪拉丁转换器;但它不是该代码的副本。 – Sergio

回答

1

(not VOWELS)值总是falsy因为VOWELS是truthy。

你的意思是写:

while word[0] in YList or (word[0] not in VOWELS):