Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/276.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
Python 这些if和else语句有什么问题?_Python_If Statement - Fatal编程技术网

Python 这些if和else语句有什么问题?

Python 这些if和else语句有什么问题?,python,if-statement,Python,If Statement,我是python新手,我正在尝试做一个调查,但当我编写这段代码时,事情进展得并不顺利 这是我长期调查的第一部分: #a program to test your adhd yes=1 YES=1 Yes=1 no=0 NO=0 No=0 print("please honestly answer the following questions","\n" "with \"yes\" or \"no\" ") a=input("1. do you have difficulty getting o

我是python新手,我正在尝试做一个调查,但当我编写这段代码时,事情进展得并不顺利 这是我长期调查的第一部分:

#a program to test your adhd
yes=1
YES=1
Yes=1
no=0
NO=0
No=0
print("please honestly answer the following questions","\n"
"with \"yes\" or \"no\" ")
a=input("1. do you have difficulty getting organized ?")#q1
if a==yes or YES or Yes or no or NO or No:
b=input("2. When given a task, you usually procrastinate rather than doing it right away")#q2    
else:
print("wrong answer")
a=input("1. do you have difficulty getting organized ?")#q1
这样做的目的是当用户写出一个正确答案时,程序就会转到下一个问题。 如果他写了其他东西,程序会打印错误的答案,然后重复问题。 但是当用Python shell和C.M.D测试时,它从不考虑(否则语句)

注意:我还不知道python中的很多东西(除了if和else语句)
因为我刚刚开始学习步骤。

请注意,
a
是一个字符串,您必须分别测试每个条件(不要忘记引号!),如下所示:

if a == 'yes' or a == 'YES' or a == 'Yes' or a == 'no' or a == 'NO' or a == 'No':
或者更简单的选择:

if a.lower() in ('yes', 'no'):

如果a==yes或a==yes或a==no,您需要
,谢谢您的回答,但我只尝试了其中一个(yes),但遇到了相同的问题。(1)您混淆了字符串和标识符(带引号和不带引号),(2)您的代码没有正确缩进,(3)您应该正确标记您的问题(这似乎是python 3,而不是2.7)。谢谢,它成功了,但我有两个问题,1-我想在调查结束时添加“是”和“否”这两个点,因此我需要用户将它们作为变量而不是字符串来编写,这就是为什么我没有使用引号的原因。2-如果用户编写错误,我如何使程序返回到第一个点?我不希望它只是重复问题,而是回到if条件。@peter 1)分别检查:如果答案是肯定的,则在计数器中加1,否则不加。2) 把所有东西都放在一个圈里。什么圈?你是说for还是while?任何你需要使它工作的循环:)可能是
while