Step 2: Keep Score ๐ข
One question is a warm-up. A quiz show needs a score! ๐ข
The trick is a variable that starts at zero and grows:
score = 0 # before any questions
score = score + 1 # every time they get one right
Read that second line right-to-left: take the old score, add 1, put it back in the box. If score was 2, it's now 3. ๐ฆ
Where does it go? Inside the if, so it only counts correct answers:
if answer == "paris":
print("โ
Correct!")
score = score + 1
Your mission
Your first question is already there. Now:
- Add
score = score + 1when they get it right - Ask 2 more questions the same way (that's 3 total)
- At the end, print their final score
Pssst โ number answers work too, they're just text: if answer == "42":
Your code
Press โถ Run to see what your code does!