Quiz Program – Part 2: adding to the quiz

Option 4 – Giving feedback on questions

You might want to get a bit funky in how you respond to a wrong answer.

Maybe you want to nudge the user in the right direction. Or maybe you want to roast them for getting it sooooo wrong.

This is somewhere we can use the if ... elif ... else  idea that you might already have used.

Code helper image
  1. Start with an if line as before and deal with the right answer first
  2. Then use an  elif  line to deal with the first wrong answer. Here I'm going to go  elif answer == "A":
  3. Then add a print statement to give the response you want if they put "A" as an answer
  4. Then carry on with the other answers. You can group two or more together if you want – that's what I've done here
  5. Then I've used the else line to deal with what happens if they enter an answer that's not A, B, C or D

You can do this with any type of question.

It works because Python will only ever pick one of the options in a set of if, elif and else commands.

So, if the user outs "C" it picks out just that set of commands. If they put "X", "Q", "I don't know" or "65", it picks out the else line and does that.