我正在做一个登录系统。它要求用户回答问题(“您已经有帐户了吗?”),虽然答案不是"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/