Times Table Tester

Step 5 – Checking the answer

Now we need to check if the answer is right.

It can be right or wrong, so there are two choices to make. This means we're using selection.

THEORY: when you use selection you choose a path through the program. If the answer's right, one thing should happen. If it's wrong, something else should happen.

Try this code.

Code helper image
  1. First, convert the answer to a number:  answer = int(answer)
  2. Then check if it's right:  if answer == number1 * number2

    Two things here: first, double equals signs. This is how Python checks if two things are equal

    Second: use * to multiply.

  3. Now we need to indent the code – this is tricky!
  4. Say "Correct" if they get the answer right
  5. Say "That's wrong" if they get the answer wrong
  6. Then tell them the right answer
  7. Run your code to check that it works

That should work, but it's difficult here so check the code really carefully, especially the indents.