2015-07-02 62 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):