Quiz Program – Part 1: the basic quiz

Step 6 – Solving problems

You should have found that when you entered "b" the program told you that the answer was right, but when you enter "B" it doesn't. Or the other way round – it depends on what you put as the answer, "b" or "B".

THEORY: This is one of those places where Python gets really picky. "B" and "b" are different to it. You need to plan for that when you check the answers, It's a LOT easier if you know how to convert an answer into all lowercase letters or all uppercase letters. Fortunately Python can do this really easily.

We're looking for an answer that should be correct if you enter either "b" or "B".

We can solve this really easily...

IMPORTANT: There are 3 ways to do this. The way you choose will depend on what you put in the if answer == line:
  • If you put "B" (an uppercase letter), use method 1
  • If you put "b" (a lowercase letter), use method 2
  • Or you can be awkward and use method 3! It's up to you...
Code helper image
  1. METHOD 1 (UPPERCASE): Change your line of code with the input on to say answer = input("Your answer > ").upper()

    This converts whatever the player types in to uppercase letters. That means that "b" becomes "B", so the IF line should now work

  2. METHOD 2 (LOWERCASE): Change your line of code with the input on to say answer = input("Your answer > ").lower()

    This converts whatever the player types in to lowercase letters. That means that "B" becomes "b", so the IF line should now work

  3. METHOD 3 (THE ALTERNATIVE): Change your line of code where you check the answer to say if answer == "B" or answer = "b":

    This checks both "B" and "b", so either are entered the answer is right

  4. Run your program: Run > Run Module and try entering "B". Python should now accept this
  5. Run your program again and try entering "b". Python should now accept this as well

You can use .lower() or .upper() on any input line just by adding them at the end.

Check your code against mine if you need to: