gpt4 book ai didi

python - 即使条件正确,while 循环也不会结束

转载 作者:行者123 更新时间:2023-11-30 22:27:53 26 4
gpt4 key购买 nike

我正在做一个登录系统。它要求用户回答问题(“您已经有帐户了吗?”),虽然答案不是"is"或“否”,但它应该继续询问。

print('Welcome to the quiz!')
print('Do you already have an account? ')
have_acc = input()
while have_acc != ('Yes') or have_acc != ('No') or have_acc != ('yes') or have_acc != ('no'):
print('Please enter Yes or No')
have_acc = input()

输出

Welcome to the quiz!
Do you already have an account?
yes
Please enter Yes or No
no
Please enter Yes or No
Yes
Please enter Yes or No
No
Please enter Yes or No

最佳答案

更规范的方法:

while input.lower() not in ('yes', 'no',):
... your retry code ...

关于python - 即使条件正确,while 循环也不会结束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46755238/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com