所以我的代码是这样的:
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不存在,反之亦然,因此它总是会导致错误。将or
更改为and
,如下所示:
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())