好吧,所以我想跟踪玩家有多少问题,但是当我说'得分= +1'时,它不会给分数增加任何东西。我该怎么做呢?这是我的代码:
score = 0
print('This is a 10 question quiz. Please do not use any capitol letters when answeringquestions'
)
print('1. Can elephants jump? (yes or no)')
answer_1 = input()
if answer_1 == 'yes':
print('Wrong! Elephants cannot jump.')
if answer_1 == 'no':
print('Correct! Elephants cannot jump!')
score = +1
print('(true or false) Karoake means \"Empty Orchestra\" In Japanese')
answer_2 = input()
if answer_2 == 'true':
print('Correct! Karoake does in fact mean \"Empty orchestra\" in Japanese')
score = +1
if answer_2 == 'false':
print('Wrong! Karoake does in fact mean \"Empty orchestra\" in Japanese')
print('Solve the math problem: What is the square root of 64?')
answer_3 = input()
if answer_3 == 8:
print('Good job! The square root of 64 is 8!')
score = +1
else:
print('Incorrect! the square root of 64 is 8.')
print(score)
答案 0 :(得分:2)
答案 1 :(得分:1)
你应该让score += 1
操作员反转。
当你说score = +1
时,你说的是将得分设为正值。
答案 2 :(得分:0)
您所写的内容score = +1
只是将'score'变量一遍又一遍地设置为正1(+1
)。
正如samrap已经说过的那样,你真的想写:
score += 1
- 将变量“得分”设置为高于score = score + 1
或 score = (score + 1)
- 将变量设置为上一个值加1(括号,虽然不是很像python,但有助于增加清晰度)