我正在編寫一個簡單的測試,應該計算用戶回答「是」和「否」的次數。這裏是我的代碼:計數滿足條件的次數(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)
目前正在輸出什麼是指示你有什麼不對? – idjaw
我的不好,我會在一秒內編輯它。它給了我'輸出:(0,0)' –
你已經在兩個地方寫了'= +',我相信你會寫'+ ='。 –