简体   繁体   中英

While loop multiple conditions not working

I tried to add a condition to where if the while loop meets a "Y" or "y" it will still move the letters to the end, but keep "Y" or "y" at the beginning, yet the loop will end and just add "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:

This is the section causing problems:

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

The value of (not VOWELS) is always falsy because VOWELS is truthy.

You meant to write:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM