Quiz Program – Part 1: the basic quiz

Code helper imageStep 7 – Adding a score

If this is a quiz then we need to include a scoring system.

This involves using a variable to keep score with.

THOERY: a variable is just an area of memory set aside to store a value. We already used a a variable – it was called answer and it stored the answer the player gave to the first question.

  1. Change your code in the three places shown in the screenshot
  2. First, set the score to 0

    If we don't do this, Python won't know that the variable score exists

  3. Then add one to it when the user gets the question right

    Score is a number (an integer data type), so it's easy to add or take away from it. If you wanted to be evil you could take a point away if the player gets the wrong answer...

  4. Then right at the bottom add the code to display the score
  5. Run your code and check that it all works
  6. You need to check what happens if you get the answer wrong and what happens if you get it right.

Make sure you test your code really carefully.