Validation 正在验证用户输入,循环从未满足?(Python 3.2.1.1)
提前感谢您的帮助。 我正在使用此代码验证我正在编写的程序的用户输入,但是用户输入永远不会满足WHILE循环,我无法理解原因Validation 正在验证用户输入,循环从未满足?(Python 3.2.1.1),validation,loops,while-loop,user-input,infinite-loop,Validation,Loops,While Loop,User Input,Infinite Loop,提前感谢您的帮助。 我正在使用此代码验证我正在编写的程序的用户输入,但是用户输入永远不会满足WHILE循环,我无法理解原因 User_Answer = input('Which is the correct answer A,B,C or D?' ).upper() #Ask user which they believe correct and save it as variable with the identifier User_Answer while User_Answer != '
User_Answer = input('Which is the correct answer A,B,C or D?' ).upper()
#Ask user which they believe correct and save it as variable with the identifier User_Answer
while User_Answer != 'A' and User_Answer !='B' and User_Answer !='C' and User_Answer !='D':
User_Answer = input('Which is the correct answer A,B,C or D?' ).upper()
# Is user entry valid in the form of A,B,C or D and re-asks question if not.
else:
do something
我可以看到一些问题。我不知道你用的是什么语言,但有一次你调用upper时没有括号,然后用括号。我在这里有点冒险,但那可能是你问题的一部分。然后似乎有一个迷路的
else
,我假设第一个else
在粘贴到这里时丢失了它的if
朋友。谢谢,我使用的是python,第一个.upper是从我的程序复制时出错的。upper后面有()在我的代码中。我换了另一个,但没什么不同。