0

Okay, so i'm trying to keep track of how many questions the player got right, but when I say 'score = +1' it adds nothing to the score. How do I do this? Here is my code:

    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)
Nick
  • 882
  • 2
  • 9
  • 31
  • Score = +1 -- I think you have the correct thought process, you just need to add the variable score in front of the "+1', like so : score = score + 1. More often than not you'll see score += 1 in people's code. *also, capitol should be spelled capital ;)* – Nick Oct 24 '13 at 01:18
  • Its been more than a week, I think that's ample time to decide if your question's been answered. Please accept one of the below answers, to both notify others that the question is answered, and merit the poster another correct answer. – Matt Reynolds Nov 02 '13 at 15:16

3 Answers3

2

score += 1

or

score = score + 1

Much better detailed answer:

Behaviour of increment and decrement operators in Python

Community
  • 1
  • 1
samrap
  • 5,595
  • 5
  • 31
  • 56
1

It should be score += 1 you have the operator reversed.

When you say score = +1 you are saying set score to positive one.

Pepe
  • 6,360
  • 5
  • 27
  • 29
0

What you're writing, score = +1, simply sets the 'score' variable to positive 1 (+1) over and over.

You really want to write, as samrap already said, either:

  • score += 1 - Sets the variable 'score' to one higher than what it was before
  • score = score + 1 OR score = (score + 1) - Sets the variable to the previous value plus 1 (The brackets, although not very python-like, help add clarity)
Matt Reynolds
  • 787
  • 2
  • 9
  • 22