Escape Room Program – Part 1: input and output

Step 3 – Asking for a name

What else did you add to your description of the room?

I think we need to ask the user to enter their name at the start of the game. This gives us a way to make the game about them.

To do that we need to use  print alongside a new command: input.

Code helper imageAsking for an input

Here's one way to ask the user to input something in Python.

  1. Add this underneath the code you already have

    Type this print code first:  print("What is your name adventurer?)
  2. Run this now. You can see that it just prints like before
  3. Now, underneath type:  input("> ")

    Don't forget the quotes (") and brackets. And do you see that I added a space after the symbol?

  4. Now run the program again. This time it waits for you to enter a name.

The > symbol is a classic way to show a player that they need to enter something in a text-based game.

You can see my finished code by clicking the button below.

I moved the code up the program to just after the title. You can copy and paste in Python easily – just use the Edit command at the top.

I also left some gaps between my code. This just makes it easier to read. Which is a good thing.