Tutorpip← About this lessonOpen the sheet →Download PDF
Ages 10+ · Coding · Python
Input from the user
The programasksPython waitsfor typingThe personpresses EnterThe answer goesin a box
Input asks, waits, and keeps the answer.
The big ideaInput pauses the program until a person types, and keeps what they type.

How it works

Input puts a question on the screen and pauses the program until a person types.

When the person presses Enter, Python carries on and the answer goes into a box, called a variable.

Input only keeps the answer. To show it, you still need print.

Whatever a person types arrives as text, even digits. A command called int turns text into a whole number.

Keeps text• name = input("Name? ")• age = input("Age? ")Keeps a number• age = int(input("Age? "))• stars = int(input("Stars? "))
Text, or a number.

Example 1: Asking for a name

  1. Zara writes the line name = input("Name? ").
  2. Python shows the question and waits.
  3. Mia types her name and presses Enter, and the answer goes into the box called name.
  4. Zara's next line prints hi, joined to the box called name, so the screen says Hi Mia.

Example 2: Digits are still text

  1. The line is age = input("Age? "), and Mia types 12.
  2. The box age holds the text 12, not a number.
  3. Python cannot add one to text, so a message pops up.

Example 3: Turning text into a number

  1. Zara changes the line to age = int(input("Age? ")).
  2. Int wraps around input and turns the typed text into a whole number.
  3. Mia types 12, and the box age holds the number 12.
  4. Now Zara can add one: 12 + 1 = 13.

Example 4: Print does not wait

  1. The line name = print("Name? ") only prints the question.
  2. Print never waits for typing, so nothing is kept.
  3. The mix-up to fix: use input, as in name = input("Name? ").

Words to know

input
A command that asks a person to type and waits.
variable
A box with a name that keeps a value.
int
A command that turns text into a whole number.
Enter
The key a person presses to say the answer is done.

Watch out

Try it

  1. Mia types 3 into the line pets = int(input("Pets? ")). Is the box pets text or a number?
  2. A visitor types 9 into the line stars = input("Stars? "). What does the box stars hold?
  3. What does Python do when it reaches an input line?
  4. Which command shows what the person typed: input or print?
  5. Mia's age is the number 12. What does Zara get when she adds one?
Answers: 1. A number · 2. The text 9 · 3. It waits for the person to type and press Enter · 4. print · 5. 13
Try at homeWith a grown-up, play ask and wait. You ask a question out loud and then stay completely still, like a paused program. They answer. You write the answer on a card, which is the box, and read it back in a full sentence, like: hi, pizza!
For grown-upsPlay the Mission together: you ask a question out loud and stay completely still, like a paused program, then write the answer on a card (the box) and read it back in a sentence.
Open these notes on screenScan the code, or go to tutorpip.com.