Spyder 4.1.4和python 3.8的正确验证循环

Spyder 4.1.4和python 3.8的正确验证循环,python,validation,Python,Validation,所以我的代码是: def main(): print("Press '1' to start a new dice roll calculation") print("or press '0' to end the program") #escape key validation = int(input()) #so the user can press enter while validation != 1 or va

所以我的代码是:

def main(): 
    print("Press '1' to start a new dice roll calculation") 
    print("or press '0' to end the program") #escape key
    validation = int(input()) #so the user can press enter
    while validation != 1 or validation != 0: #input validation loop with escape key
        print("Press ENTER to start a new dice roll calculation")
        validation = int(input())
    

当我出于某种原因尝试运行验证循环时,它将我带入无限循环,但当我检查教科书时(Tony Gaddis,2017),它应该是正确的。我哪里错了?

它正在检查1或0是否不存在。如果键入1,则0不存在,反之亦然,因此它将始终导致错误。将
更改为
,如下所示:

def main(): 
    print("Press '1' to start a new dice roll calculation") 

    print("or press '0' to end the program") #escape key

    validation = int(input()) #so the user can press enter

    #input validation loop with escape key using AND instead of OR
    while validation != 1 and validation != 0: 
        print("Press ENTER to start a new dice roll calculation")
        validation = int(input())

如果条件应该是
,而不是
。(如果他们输入1,它就不等于0,如果他们输入0,它就不等于1。所以对于
条件,是的,它是一个无限循环。)它总是非常简单的。非常感谢。