← Teacher guide

Ask and store

Students meet input, store the typed answer in a name, and use it in the reply.

Console bridge: text in, text out · Text in, text out · about 30 minutes · Open the student lesson

Classroom resources

Load these into Waypoints Prepare: choose Load URL and paste the copied address, or download the file and import it. In Prepare, the worksheet's Teacher edition shows the answers; the student copy hides them.

Students will be able to

Timing

Predict and Run 8 min · Investigate 8 min · Make 14 min

Running the lesson

  1. Predict: take a vote before running. Wrong options: the name as a word, the prompt stored in the name, no answer at all. Ask one pair from each option to explain: the question is shown, not stored.
  2. Run: students run it several times with different answers. Ask: what changed each time, and what stayed the same?
  3. Investigate: the bug is a very common first slip. Ask what happened to the typed text.
  4. Make: students choose their own two questions. Circulate and ask each to read the program aloud, line by line.

The hard part (on purpose)

Remembering that input needs a name to catch the answer. Ask where the typed text went.

When students get stuck

What you will seeA question to askThe fix
A NameError on the first line that uses the answer.Which line stores what was typed?Write name = in front of input so the answer is stored under that name.
The question shows but there is no space before the answer.What is inside the quotes of the question?End the question text with a space, such as "Name? ".

Answers to the checks

  1. Predict: You run it and type Ada. What does the last line show?
    Hello, Ada. input gives back what was typed, and name = stores it. The last line joins Hello, onto whatever name holds, which is Ada.
  2. Follow the answer: Fill in what name holds and what the last line shows for each answer.
    Sam, Hello, Sam, 42, Hello, 42
    Whatever is typed is stored as text and shown back as typed, even digits.
  3. Spot the bug: The program asks, but then stops with a NameError on line 2. Click the line that needs to change.
    line 1
    The answer was typed but not stored: no name catches it. name = input(...) puts the answer in name.

Solutions

One possible solution for each task. Other correct programs are fine.

Make

name = input("What is your name? ")
animal = input("What is your favourite animal? ")
print(name + " likes the " + animal + ".")

Stretch and support

Stretch: Ask for three things and print a card with one line per answer.

Support: Give the first question and ask the student to add the second.

Exit ticket

What is the difference between input("Name? ") on its own and name = input("Name? ")?

Both ask and wait. Only the second stores the answer, so the program can use it.

What each step is for

Where it leads

Next lesson: the answer is always text, so adding a typed number to a number fails. Joining numbers onto text takes str.