简体   繁体   English

虽然循环多个条件不起作用

[英]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" 我试图添加一个条件,如果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:

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. (not VOWELS)值始终是虚假的,因为VOWELS是真实的。

You meant to write: 您打算写:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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