Quiz Program – Part 1: the basic quiz

Step 5 – Checking the answer

We've asked a question and got an answer from the player. We'd better check that the answer is correct or not.

Code helper image
  1. Add the code in the screenshot after the question

    Take care here. The : at the end of two of the lines are really important (the : is called a colon by the way).

    And the indents are really important as well. You might remember these from using micro:bits...

    And did you notice the  ==   That's two equals signs one after another

    And see that I added a comment and left a gap to make things easier to read

  2. Run your program and see what happens.

    When you get to type what you want to do, you need to try typing each of these options (you'll need to run the program more than once):

    • "a"
    • "b" (the right answer)
    • "B" (also the right answer)
    • "e"
    • "I don't know"

    What happens each time? Is this OK or are there some problems here?

  3. Can you improve the messages the player gets?

THEORY: This uses an if – else block of code. These allow us to make decisions about what happens next. This is a process called selection and is a really important part of writing a computer program.
I stored the answer the user typed in in a variable called answer. That's what I'm checking here - have them given the same answer that I'm looking for or is their answer different?

We'll try and solve some of the problems in the next step...