Escape Room Program – Part 1: input and output

Step 8 – Action

The player told us what they wanted to do. We should decide if they can do it or not!

It's dark, so at this stage of the program I think the only thing the player should be able to do is to turn a light on. Working out this can be the first riddle.

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

    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

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

    • "light"
    • "get up"
    • "Light"
    • "Turn the light on"

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

  3. Can you improve your descriptions? What will the player see in the room? What will you tell them if they don't say "light"?

    You might want to use more than one print statement here. Don't forget blank lines...

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.

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