Escape Room Program – Part 1: input and output

Step 4 – Using the name

We can get the user to enter their name. But the name isn't stored anywhere, so we can't use it in our program.

To store it we need to use a variable.

Code helper image
  1. Change the line of code with the input to:  player = input("> ")
  2. Now run the code

Make sure you change the code. Don't just add this on the bottom.

It won't seem to make a difference, but the name is stored somewhere in the computer.

Now let's use the name:

A variable is just an area of computer memory where something can be stored.

If we can store it then the computer can remember it. So we can use it again – just like the score in a game or a quiz.

The way we reuse it is a bit clever.

Code helper image
  1. After the code where you get the player to enter their name, add a line of code that says:  print(player)

    This won't print the word "player", it will print whatever is stored inside the variable player. Clever.

  2. Run your program again and check that's what happens

It's really important to make sure you spell the variable name right each time. Otherwise you'll get an error message.