2017-07-22 138 views
-3

我正在编写一个简单的测试,应该计算用户回答“是”和“否”的次数。这里是我的代码:计数满足条件的次数(Python)

questions = ["Are you happy?", "Did you shower?", "Are you Turkish?", "Are you bored?", "Do you have friends?"] 

yes = 0 
no = 0 

for each in questions: 
    answers = input(each) 
    if answers == "yes": 
     yes =+ 1 
    elif answers == "no": 
     no =+ 1 

print(yes, no) 

要么回答“是”或“否”的问题,回答的Python Output: (0,0)

我在做什么错后?

编辑:我得到确切的输出是在这里:

[email protected]:~/enviroments$ python quiz.py 
Are you happy?yes 
Did you shower?no 
Are you Turkish?yes 
Are you bored?no 
Do you have friends?yes 
(0, 0) 
+1

目前正在输出什么是指示你有什么不对? – idjaw

+0

我的不好,我会在一秒内编辑它。它给了我'输出:(0,0)' –

+2

你已经在两个地方写了'= +',我相信你会写'+ ='。 –

回答

0

@RafaelMartínez!

您的程序会颠倒增强的赋值运算符。它应该是+=,而不是=+

比如你行

yes =+ 1 

实际上是设置1到变量yes,在一个没有增加其先前的值。

我不知道这是可能的。感谢这个有趣的例子。

0

的问题是,你有= +而不是+ =。如果您将其更改为+ =,它将起作用

+0

它为我工作 –