Riddle me this – it's all Greek to me

Step 5 – Checking the answer

We've asked a riddle and got an answer. Now we need to check if the answer is right or not.

To do this we need to use an if – else block.

This is a basic way to do this. We'll look at a much more complex way of doing it in the next part.

Code helper image
  1. Add the code in the screenshot at the bottom of your program

    The indents are really important

    Use the Tab key on the keyboard to indent quickly

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

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

  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):

    • "Man"
    • "man"
    • "MAN"
    • "A man"

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

An if – else block of code 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.

Solving the problem

The problem is that Python thinks that "Man" and "man" are different things. To us they mean the same, but things like capital letters really matter to Python.

There's a easy way to solve this:

Code helper image
  1. CHANGE your line of code with the input on to say:
    answer = input("> ").lower()

    This converts whatever the player types in to lower case letters. That means that "MAN" or "Man" become "man", so the IF line should now work

  2. Run your program: Run > Run Module and try entering "MAN". Python should now accept this

You can use .lower() on any input line just by adding it at the end. You can also use .upper() if you need to convert to upper case letters.