Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Validation 正在验证用户输入,循环从未满足?(Python 3.2.1.1)_Validation_Loops_While Loop_User Input_Infinite Loop - Fatal编程技术网

Validation 正在验证用户输入,循环从未满足?(Python 3.2.1.1)

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 != '

提前感谢您的帮助。

我正在使用此代码验证我正在编写的程序的用户输入,但是用户输入永远不会满足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 != '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后面有()在我的代码中。我换了另一个,但没什么不同。