Python while循环使用或不提供已消耗的输出

Jag*_*ght 0 python logic while-loop

这是我的循环:

sure = input('Are you sure that you wish to reset the program?(y/n)')
while sure != 'y' or sure != 'n':
    sure = input('Please awnser y or n, Are you sure that you wish to reset the program?(y/n)')
Run Code Online (Sandbox Code Playgroud)

循环持续进行,即使循环y或者n被输入.

Cor*_*mer 5

将条件更改为

while sure != 'y' and sure != 'n':
Run Code Online (Sandbox Code Playgroud)

无论他们输入什么,你写的条件总是如此True.另一种选择

while sure not in ('y','n'):
Run Code Online (Sandbox Code Playgroud)