Book a free demo

🐍 Python for beginners · session 3 of 57 · 60 minutes

Talking to the user: input() and types

Programs become fun when they talk to you. Ask a question with input(), turn the answer into a number, and build programs that work for any answer, practising each step as you go.

🖨 Practice sheet

A complete lesson · 60 minutes

Teach it, see it, practise it, all on this page.

Open this page with your learner and work down it, or press Teach this lesson to go through it one step at a time on a big screen. Every section has something to do.

See the teacher's plan
  1. Warm-up4 min
  2. Asking a question7 min
  3. Text or number?9 min
  4. Convert straight away8 min
  5. Calculators7 min
  6. Age in 20408 min
  7. Pizza planner8 min
  8. Story machine5 min
  9. Quiz3 min
  10. Set the project1 min

By the end you can

  • Ask a question with input() and store the answer
  • Explain why input() always gives text
  • Convert with int(), float() and str()
  • Build calculators and planners that work for any input

Before you start

  • Session 2: variables and f-strings

Have ready

  • This page (type answers in the Input box under each editor, one per line)

Beginner · ages 10 and up

Warm-up · think first

A form asks "How old are you?" and you type 11. Then it asks "How old will you be in 5 years?" Can the computer add 5 to what you typed straight away? What might go wrong?

Show the answer

What you type arrives as text, like a word. Adding 5 to the word "11" makes no sense, so the program must first turn the text into a number.

Teacher tip: Write "11" and 11 on paper: which is a word made of characters, and which is a number you can add to?

Part 1 of 4 · learn, see, practise

Asking a question

input("question") shows the question, waits for an answer and gives it back. Store it in a variable.

On this page, type answers in the Input box, one per line, then press Run. The program takes the next line each time it asks.

Example: run it, then change it

Output

What is your name? Asha
Hello, Asha! Nice to meet you.

Memory boxes

name'Asha'str

Change Asha to your name and run again.

Practise it

Start with the warm-up and go as far as you can. The stretch questions are meant to be hard.

Warm-up

1.1 Ask for a name and print Welcome, <name>!

Task 1.1

Output

(nothing is printed)

Memory boxes

No variables yet
Model answer (for the teacher)
name = input("Name? ")
print(f"Welcome, {name}!")
Core

1.2 Ask for a colour, then an animal. Print: Your <colour> <animal> is ready.

Task 1.2

Output

(nothing is printed)

Memory boxes

No variables yet
Model answer (for the teacher)
c = input("Colour? ")
a = input("Animal? ")
print(f"Your {c} {a} is ready.")
Stretch 🔥

1.3 Ask for three words, then print them in reverse order on one line, separated by spaces.

Task 1.3

Output

(nothing is printed)

Memory boxes

No variables yet
Model answer (for the teacher)
a = input("1? ")
b = input("2? ")
c = input("3? ")
print(c, b, a)

Part 2 of 4 · learn, see, practise

input() always gives text

input() gives back a string even if digits are typed. "11" + "5" is "115".

int("11") makes the whole number 11; float("2.5") makes a decimal number; str(11) makes text again.

Example: run it, then change it

Output

First number: 11
Second number: 5
Joined as text: 115
Added as numbers: 16

Memory boxes

a'11'strb'5'str

Same answers, very different results.

Practise it

Start with the warm-up and go as far as you can. The stretch questions are meant to be hard.

Warm-up

2.1 Read two numbers and print their sum as the last line.

Task 2.1

Output

(nothing is printed)

Memory boxes

No variables yet
Model answer (for the teacher)
a = int(input("a? "))
b = int(input("b? "))
print(a + b)
Core

2.2 Read a whole number n. Print n joined with itself as text, then n doubled as a number, on the last two lines (for 5: 55 then 10).

Task 2.2

Output

(nothing is printed)

Memory boxes

No variables yet
Model answer (for the teacher)
n = input("n? ")
print(n + n)
print(int(n) * 2)
Stretch 🔥

2.3 Read the side of a square. Print Area: … and Perimeter: … as the last two lines.

Task 2.3

Output

(nothing is printed)

Memory boxes

No variables yet
Model answer (for the teacher)
s = int(input("Side? "))
print(f"Area: {s * s}")
print(f"Perimeter: {4 * s}")

Part 3 of 4 · learn, see, practise

Convert straight away

Convert as you read: age = int(input("Age? ")). Use int for whole numbers and float for anything with a decimal point.

If someone types a word where a number is expected, int() stops with a ValueError.

Example: run it, then change it

Output

How old are you? 11
In 5 years you will be 16.
Your height in metres? 1.45
Twice your height is 2.9 m.

Memory boxes

age11intheight1.45float

Look at the memory boxes: age is an int, height a float.

Practise it

Start with the warm-up and go as far as you can. The stretch questions are meant to be hard.

Warm-up

3.1 Read an age and print: Next year you will be <age + 1>.

Task 3.1

Output

(nothing is printed)

Memory boxes

No variables yet
Model answer (for the teacher)
age = int(input("Age? "))
print(f"Next year you will be {age + 1}.")
Core

3.2 Read a price (decimal) and a quantity (whole). Print Total: and the cost.

Task 3.2

Output

(nothing is printed)

Memory boxes

No variables yet
Model answer (for the teacher)
p = float(input("Price? "))
q = int(input("Qty? "))
print(f"Total: {p * q}")
Stretch 🔥

3.3 Read a temperature in °C and print it in °F (F = C × 9 / 5 + 32) as the last line, just the number.

Task 3.3

Output

(nothing is printed)

Memory boxes

No variables yet
Model answer (for the teacher)
c = float(input("C? "))
print(c * 9 / 5 + 32)

Part 4 of 4 · learn, see, practise

Calculators that work for anyone

Put it together: read, convert, calculate, print. The program has no numbers of its own any more: it works for whatever is typed.

Example: run it, then change it

Output

First number: 7
Second number: 2
7.0 + 2.0 = 9.0
7.0 x 2.0 = 14.0
7.0 / 2.0 = 3.5

Memory boxes

a7.0floatb2.0float

Try other numbers. What happens with 0 as the second number?

Practise it

Start with the warm-up and go as far as you can. The stretch questions are meant to be hard.

Warm-up

4.1 Read two whole numbers and print their product as the last line.

Task 4.1

Output

(nothing is printed)

Memory boxes

No variables yet
Model answer (for the teacher)
a = int(input())
b = int(input())
print(a * b)
Core

4.2 Read a bill and the number of people. Print Each pays: and the share.

Task 4.2

Output

(nothing is printed)

Memory boxes

No variables yet
Model answer (for the teacher)
bill = float(input("Bill? "))
n = int(input("People? "))
print(f"Each pays: {bill / n}")
Stretch 🔥

4.3 Read a number of seconds and print it as minutes and seconds, like 2 min 10 sec, as the last line.

Task 4.3

Output

(nothing is printed)

Memory boxes

No variables yet
Model answer (for the teacher)
s = int(input("Seconds? "))
print(f"{s // 60} min {s % 60} sec")

Watch out

Common mistakes

Adding text

"3" + "4" is "34". Convert with int() or float() first.

Converting too late

Convert once when you read the value.

Missing a bracket

int(input("Age? ") is missing a closing bracket: two opened, two closed.

Class activity 1 of 3

Age in the year 2040

Ask for a name and a birth year. The last two lines must be: Hi <name>! and In 2040 you will be <age>.

  1. Read the name.
  2. Read the birth year and convert it with int().
  3. Work out age = 2040 - year.
  4. Print the two lines with f-strings.
Your code

Output

Your name? Asha
Year you were born? 2014

Memory boxes

name'Asha'stryear'2014'str
Hint

year = int(input(...))

Model answer (for the teacher)
name = input("Your name? ")
year = int(input("Year you were born? "))
age = 2040 - year
print(f"Hi {name}!")
print(f"In 2040 you will be {age}.")

Class activity 2 of 3

Pizza party planner

Read the number of guests and how many slices each eats. A pizza has 8 slices. The last three lines must be: Slices: …, Pizzas: … (enough pizzas, rounded up) and Spare slices: ….

  1. Read guests and slices each, as whole numbers.
  2. slices = guests × slices each.
  3. pizzas = (slices + 7) // 8 rounds up to whole pizzas.
  4. spare = pizzas × 8 - slices.
  5. Print the three lines.
Your code

Output

Guests? 10
Slices each? 3

Memory boxes

guests10inteach3int
Hint

For 30 slices: (30 + 7) // 8 = 4 pizzas.

Model answer (for the teacher)
guests = int(input("Guests? "))
each = int(input("Slices each? "))
slices = guests * each
pizzas = (slices + 7) // 8
spare = pizzas * 8 - slices
print(f"Slices: {slices}")
print(f"Pizzas: {pizzas}")
print(f"Spare slices: {spare}")

Class activity 3 of 3

Story machine

Read a name, an animal, a place and a food. Print a story of at least three lines. The first story line must be exactly: Once upon a time, <name> the <animal> lived on <place>.

  1. Read the four words.
  2. Print the first line exactly as shown, with an f-string.
  3. Add at least two more lines that use the place and the food.
  4. Run it with silly words and read it aloud!
Your code

Output

A name? Zoe
An animal? tiger
A place? Mars
A food? pizza

Memory boxes

name'Zoe'stranimal'tiger'strplace'Mars'strfood'pizza'str
Hint

The four questions print four lines first, so the story starts on line 5.

Model answer (for the teacher)
name = input("A name? ")
animal = input("An animal? ")
place = input("A place? ")
food = input("A food? ")
print(f"Once upon a time, {name} the {animal} lived on {place}.")
print(f"Every day {name} ate {food} for breakfast.")
print(f"One day the {food} ran out on {place}...")

Quiz · 8 questions

Check what you learned

Pick an answer to see if it is right and why. Your best score is saved on this device.

1What does this show?
print("7" + "3")
Show the answer

73. Two strings joined.

2What does this show?
print(int("7") + 3)
Show the answer

10. int("7") is the number 7.

3What does this show?
print(str(5) + "5")
Show the answer

55. str(5) is text.

4What does this show?
print(float("2.5") * 2)
Show the answer

5.0. A float answer: 5.0.

5What does this show?
print(int(3.9))
Show the answer

3. int() cuts off the decimal part.

6What does input() give back?
Show the answer

Always text (a string). Convert it when you need a number.

7Which line reads a whole number?
Show the answer

n = int(input("n? ")). Read with input, convert with int.

8What does this show?
print("3" * 3)
Show the answer

333. A string times a number repeats it.

After class · project

Unit converter

Build a converter that asks for kilometres and °C and converts them to miles and °F, then add a converter of your own.

What to make: A program that asks at least three questions and prints at least three conversions.

Stretch: Use round(miles, 2) to show two decimal places.

How it is marked

Look forDone well when
InputEvery value is read and converted
FormulasAll conversions are correct
Clear outputEach answer is a sentence with units
Own ideaOne extra converter

Starter code to take home

Press Copy and paste it into the editor at home, or work on it right here.

Project starter

Output

Distance in km: Line 2: EOFError: EOF when reading a line (there is no more input; add lines to the Input box)

Memory boxes

No variables yet

Homework

Practise at home

Each one checks itself. Or print the practice sheet.

Warm-up

1. Read a number and print its square as the last line.

Homework 1

Output

(nothing is printed)

Memory boxes

No variables yet
Core

2. Read the length and width of a room (decimals allowed) and print the area as the last line.

Homework 2

Output

(nothing is printed)

Memory boxes

No variables yet
Stretch 🔥

3. Read the marks of three tests. Print the total and then the average, as the last two lines.

Homework 3

Output

(nothing is printed)

Memory boxes

No variables yet

For parents and teachers

The 60-minute lesson plan

Use it as it is, or stretch any part over two sessions. Each row links to the part of the page you need.

TimePartThe teacherThe learner
0–4 minWarm-up"11" vs 11 on paper.Explain the difference.
4–11 minAsking a questionShow the Input box.Reverse-words stretch.
11–20 minText or number?Joined vs added.Square area stretch.
20–28 minConvert straight awayMake a ValueError happen.Temperature stretch.
28–35 minCalculatorsAsk about dividing by 0.Seconds stretch.
35–43 minAge in 2040Watch them use the Input box.Pass all checks.
43–51 minPizza plannerDiscuss rounding up.Pass all checks.
51–56 minStory machineRead stories aloud.Write a story.
56–59 minQuizRun the quiz.Answer.
59–60 minSet the projectOpen the converter starter.Choose an extra converter.

Questions to ask

  • Why does "11" + "5" give 115?
  • When do you use float() instead of int()?
  • How do you round up a division to whole pizzas?

If it feels hard

Use paper cards for "11" and 11 and physically join or add them.

If it feels easy

Build a tip calculator: bill and tip percent in, tip and total out.

FAQ

Talking to the user: input() and types: questions

Why does Python input() return a string?

The keyboard sends characters, so input gives text and you convert it with int() or float().

How do I read a number from the user in Python?

Wrap input in int() or float(): age = int(input("Age? ")).

How does the Input box work on this page?

Each line is one answer, used in order whenever the program asks.

Start a conversation

Want a teacher to take this class?

Tell us the learner's age and level. A teacher from our network teaches with these lessons; we confirm timing and price first.

  • Tell us the learner’s age or grade and goals
  • We’ll suggest a suitable class or learning path
  • We’ll confirm format, timing and fees with a parent or guardian

For a child’s class, please have a parent or guardian send the enquiry. Avoid sharing passwords or sensitive personal details.

We’ll use your details only to respond to this request.

Chat on WhatsApp
Esc

Try