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.
SlidesDownload Present from the browser, or export to PowerPoint or PDF.
WorksheetDownload Print the student copy; the Teacher edition has the answers.
Students will be able to
I can ask a question with input and store the answer in a name.
I can use the stored answer in what the program prints.
I can say that what is typed comes back as text.
Timing
Predict and Run 8 min · Investigate 8 min · Make 14 min
Running the lesson
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.
Run: students run it several times with different answers. Ask: what changed each time, and what stayed the same?
Investigate: the bug is a very common first slip. Ask what happened to the typed text.
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 see
A question to ask
The 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
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.
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.
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
Investigate: input hands back whatever was typed. If you do not store it in a name, it is gone.
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.