Skip to content
← Back to Community
How do I add a score?
Profile icon
pyraminx

Hello,
I’m a little bit in trouble with that basic project. It’s a simple quiz (about the Rubik’s Cube (-:). I wanted to add a score (if the answer is correct +1, if it’s false -1). But it doesn’t count properly (the score), because it’s in a def statement. But I have no idea how to fix that. Maybe you could help me!? If you want to, you maybe also could give me some tips (improvements) for that code!?
Thanks in advance!
Have a nice day! (-:

Answered by robowolf [earned 5 cycles]
View Answer
Voters
Profile icon
DesmondSaypannh
Profile icon
SaraAHMAD3
Profile icon
Alf13AEH
Profile icon
MollyMaitland
Profile icon
jessiebear52
Profile icon
pyraminx
Comments
hotnewtop
Profile icon
robowolf

It should be points -=1/+=1 not points =-1/=+1. This assigns the variable to either -1 or 1 rather than adding it.

Profile icon
RYANTADIPARTHI

Solution

all you have to do is to make a variable, and increment it, whenever something happened.

score = 0 if something: score += 1

like that.
That should work

Profile icon
HermioneGrange2

You need to add points like this:

score = 0 question = input('ksljafoiwahgsdaf?') question = int(question) if question = True: score += 1 elif question = False: score -= 1 print(score)