0

好的,所以我试图记录玩家有多少问题是正确的,但是当我说'score = +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)
4

3 回答 3

2

score += 1

或者

score = score + 1

更好的详细答案:

Python中递增和递减运算符的行为

于 2013-10-24T01:14:13.807 回答
1

应该是score += 1您将操作员颠倒过来。

当你说score = +1你是说设置分数为正数时。

于 2013-10-24T01:14:39.527 回答
0

你在写什么,只是一遍又一遍地score = +1将'score'变量设置为正1( )。+1

正如 samrap 已经说过的那样,您真的想写:

  • score += 1- 将变量“分数”设置为比以前高一
  • score = score + 1 score = (score + 1)- 将变量设置为前一个值加 1(括号,虽然不是很像 python,但有助于增加清晰度)
于 2013-10-24T01:33:30.397 回答