Python 循环赢了';当我想要的时候,你不会停止重复吗?

Python 循环赢了';当我想要的时候,你不会停止重复吗?,python,while-loop,Python,While Loop,这段代码应该要求用户输入,如果他们没有输入五个字符串中的一个,那么它应该一直询问,直到他们输入为止。但是,当我添加while循环来完成此任务时,它无法识别有效的输入,它仍然会继续循环输入 def main(): print('----- AVATAR -----') avatar = input('Select an Avatar or create your own:\n') #if input is not one of these V then it should

这段代码应该要求用户输入,如果他们没有输入五个字符串中的一个,那么它应该一直询问,直到他们输入为止。但是,当我添加while循环来完成此任务时,它无法识别有效的输入,它仍然会继续循环输入

def main():
    print('----- AVATAR -----')

    avatar = input('Select an Avatar or create your own:\n')
    #if input is not one of these V then it should keep asking
    #if input is one of these, go to if statements
    while (avatar != 'exit' or avatar != 'Jeff' or 'custom' or 'Chris' or 'Adam'):
        avatar = input('Select an Avatar or create your own:\n')

    if avatar == 'exit':
        return avatar
    elif avatar == 'Jeff':
        hat('both')
        face("True", "0")
        arm_style("=")
        torso_length(2)
        leg_length(2)
        shoe_style("#HHH#")
    elif avatar == 'Adam':
.....

然后所有5个有效输入都有elif语句

循环的代码不正确。它必须是以下内容:

while (avatar != 'exit' and avatar != 'Jeff' and avatar !='custom' and avatar !='Chris' and avatar !='Adam'):

这可能是因为在while子句中,您停止检查“avatar!”只有“或”自定义“和“或”克里斯”等


这相当于说“或字符串”。布尔检查中的非空字符串本身的计算结果为“true”。因此,您的while循环具有常量“true”值,这是因为您没有检查字符串是否等于某个值,而只是检查字符串是否等于某个值。

请正确设置代码格式。您需要继续定义while语句来显式检查变量。
s必须是
s。