🐍 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.
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.
- Warm-up4 min
- Asking a question7 min
- Text or number?9 min
- Convert straight away8 min
- Calculators7 min
- Age in 20408 min
- Pizza planner8 min
- Story machine5 min
- Quiz3 min
- 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.
Output
What is your name? Asha Hello, Asha! Nice to meet you.
Memory boxes
'Asha'strChange 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.
1.1 Ask for a name and print Welcome, <name>!
Output
(nothing is printed)
Memory boxes
Model answer (for the teacher)
name = input("Name? ")
print(f"Welcome, {name}!")1.2 Ask for a colour, then an animal. Print: Your <colour> <animal> is ready.
Output
(nothing is printed)
Memory boxes
Model answer (for the teacher)
c = input("Colour? ")
a = input("Animal? ")
print(f"Your {c} {a} is ready.")1.3 Ask for three words, then print them in reverse order on one line, separated by spaces.
Output
(nothing is printed)
Memory boxes
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.
Output
First number: 11 Second number: 5 Joined as text: 115 Added as numbers: 16
Memory boxes
'11'strb'5'strSame 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.
2.1 Read two numbers and print their sum as the last line.
Output
(nothing is printed)
Memory boxes
Model answer (for the teacher)
a = int(input("a? "))
b = int(input("b? "))
print(a + b)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).
Output
(nothing is printed)
Memory boxes
Model answer (for the teacher)
n = input("n? ")
print(n + n)
print(int(n) * 2)2.3 Read the side of a square. Print Area: … and Perimeter: … as the last two lines.
Output
(nothing is printed)
Memory boxes
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.
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
11intheight1.45floatLook 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.
3.1 Read an age and print: Next year you will be <age + 1>.
Output
(nothing is printed)
Memory boxes
Model answer (for the teacher)
age = int(input("Age? "))
print(f"Next year you will be {age + 1}.")3.2 Read a price (decimal) and a quantity (whole). Print Total: and the cost.
Output
(nothing is printed)
Memory boxes
Model answer (for the teacher)
p = float(input("Price? "))
q = int(input("Qty? "))
print(f"Total: {p * q}")3.3 Read a temperature in °C and print it in °F (F = C × 9 / 5 + 32) as the last line, just the number.
Output
(nothing is printed)
Memory boxes
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.
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
7.0floatb2.0floatTry 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.
4.1 Read two whole numbers and print their product as the last line.
Output
(nothing is printed)
Memory boxes
Model answer (for the teacher)
a = int(input())
b = int(input())
print(a * b)4.2 Read a bill and the number of people. Print Each pays: and the share.
Output
(nothing is printed)
Memory boxes
Model answer (for the teacher)
bill = float(input("Bill? "))
n = int(input("People? "))
print(f"Each pays: {bill / n}")4.3 Read a number of seconds and print it as minutes and seconds, like 2 min 10 sec, as the last line.
Output
(nothing is printed)
Memory boxes
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>.
- Read the name.
- Read the birth year and convert it with int().
- Work out age = 2040 - year.
- Print the two lines with f-strings.
Output
Your name? Asha Year you were born? 2014
Memory boxes
'Asha'stryear'2014'strHint
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: ….
- Read guests and slices each, as whole numbers.
- slices = guests × slices each.
- pizzas = (slices + 7) // 8 rounds up to whole pizzas.
- spare = pizzas × 8 - slices.
- Print the three lines.
Output
Guests? 10 Slices each? 3
Memory boxes
10inteach3intHint
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>.
- Read the four words.
- Print the first line exactly as shown, with an f-string.
- Add at least two more lines that use the place and the food.
- Run it with silly words and read it aloud!
Output
A name? Zoe An animal? tiger A place? Mars A food? pizza
Memory boxes
'Zoe'stranimal'tiger'strplace'Mars'strfood'pizza'strHint
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.
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 for | Done well when |
|---|---|
| Input | Every value is read and converted |
| Formulas | All conversions are correct |
| Clear output | Each answer is a sentence with units |
| Own idea | One extra converter |
Starter code to take home
Press Copy and paste it into the editor at home, or work on it right here.
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
Homework
Practise at home
Each one checks itself. Or print the practice sheet.
1. Read a number and print its square as the last line.
Output
(nothing is printed)
Memory boxes
2. Read the length and width of a room (decimals allowed) and print the area as the last line.
Output
(nothing is printed)
Memory boxes
3. Read the marks of three tests. Print the total and then the average, as the last two lines.
Output
(nothing is printed)
Memory boxes
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.
| Time | Part | The teacher | The learner |
|---|---|---|---|
| 0–4 min | Warm-up | "11" vs 11 on paper. | Explain the difference. |
| 4–11 min | Asking a question | Show the Input box. | Reverse-words stretch. |
| 11–20 min | Text or number? | Joined vs added. | Square area stretch. |
| 20–28 min | Convert straight away | Make a ValueError happen. | Temperature stretch. |
| 28–35 min | Calculators | Ask about dividing by 0. | Seconds stretch. |
| 35–43 min | Age in 2040 | Watch them use the Input box. | Pass all checks. |
| 43–51 min | Pizza planner | Discuss rounding up. | Pass all checks. |
| 51–56 min | Story machine | Read stories aloud. | Write a story. |
| 56–59 min | Quiz | Run the quiz. | Answer. |
| 59–60 min | Set the project | Open 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