🐍 Python for beginners · session 2 of 57 · 60 minutes
Variables: boxes that remember
Teach Python to remember things. Variables are named boxes that hold a value; make them, change them, do maths with them and print them neatly, practising each idea before the next.
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
- Making a variable8 min
- Changing a variable7 min
- Operators10 min
- f-strings6 min
- Shop bill8 min
- Time converter7 min
- Report card6 min
- Quiz3 min
- Set the project1 min
By the end you can
- Create a variable and explain what = does
- Change a variable using its old value
- Use + - * / // % and **
- Print values neatly with an f-string
- Write programs that still work when a value changes
Before you start
- Session 1: print(), text and numbers
Have ready
- This page
- A few sticky notes to act as boxes
Beginner · ages 10 and up
Warm-up · think first
Write "score" on a sticky note and put 0 on it. A game says: add 10, add 5, then double it. What is on the note at the end? Did you need to remember the earlier numbers?
Show the answer
30. Only the latest value matters: 0 → 10 → 15 → 30. A variable is exactly that: a name with one value inside that can be replaced.
Teacher tip: Do it physically: cross out and write the new value each time.
Part 1 of 4 · learn, see, practise
Making a variable
A variable is a name that holds a value, like a labelled box: age = 11. In Python = means "put the value on the right into the box on the left".
Wherever you write the name, Python uses the value inside. Names use letters, numbers and _, cannot start with a number and cannot contain spaces.
Output
Riya Riya is 11
Memory boxes
'Riya'strage11intLook at the memory boxes under the output: name and age.
Practise it
Start with the warm-up and go as far as you can. The stretch questions are meant to be hard.
1.1 The variable name is already made. Print Hello, followed by the name (use a comma).
Output
(nothing is printed)
Memory boxes
'Zara'strModel answer (for the teacher)
name = "Zara"
print("Hello,", name)1.2 Make a = 6 and b = 7 and print their product.
Output
(nothing is printed)
Memory boxes
Model answer (for the teacher)
a = 6
b = 7
print(a * b)1.3 price = 40 and qty = 3. Print Cost: and the cost.
Output
(nothing is printed)
Memory boxes
40intqty3intModel answer (for the teacher)
price = 40
qty = 3
print("Cost:", price * qty)1.4 side = 5. Print two lines: Area: … and Perimeter: … of a square with that side.
Output
(nothing is printed)
Memory boxes
5intModel answer (for the teacher)
side = 5
print("Area:", side * side)
print("Perimeter:", 4 * side)Part 2 of 4 · learn, see, practise
Changing a variable
Giving a variable a new value replaces the old one. score = score + 10 means: take what is in score, add 10, put it back.
Shortcuts: score += 10 adds, -= subtracts, *= multiplies.
Output
Final score: 30
Memory boxes
30intThe sticky-note warm-up as code. Each line replaces the value in the box.
Practise it
Start with the warm-up and go as far as you can. The stretch questions are meant to be hard.
2.1 score starts at 0. Add 5 three times using += and print score.
Output
(nothing is printed)
Memory boxes
0intModel answer (for the teacher)
score = 0
score += 5
score += 5
score += 5
print(score)2.2 money = 100. Spend 35, earn 20, then double what is left. Print money.
Output
(nothing is printed)
Memory boxes
100intModel answer (for the teacher)
money = 100
money -= 35
money += 20
money *= 2
print(money)2.3 Swap the values of a and b, then print a and b on one line. (Hint: a third box.)
Output
(nothing is printed)
Memory boxes
1intb2intModel answer (for the teacher)
a = 1
b = 2
temp = a
a = b
b = temp
print(a, b)Part 3 of 4 · learn, see, practise
Maths operators
// divides and drops the remainder, % gives only the remainder, ** is "to the power of". / always gives a decimal answer.
% is a super tool: n % 10 is the last digit of n, n % 2 tells odd or even, and minutes % 60 is the minutes left after whole hours.
Output
2 hours and 15 minutes 2.5 32
Memory boxes
135inthours2intleft15int135 minutes is 2 hours and 15 minutes.
Practise it
Start with the warm-up and go as far as you can. The stretch questions are meant to be hard.
3.1 Print 17 // 5 on one line and 17 % 5 on the next.
Output
(nothing is printed)
Memory boxes
Model answer (for the teacher)
print(17 // 5)
print(17 % 5)3.2 sweets = 47 are shared equally by kids = 6. Print Each: … and Left: ….
Output
(nothing is printed)
Memory boxes
47intkids6intModel answer (for the teacher)
sweets = 47
kids = 6
print("Each:", sweets // kids)
print("Left:", sweets % kids)3.3 n = 2468. Print its last digit using %.
Output
(nothing is printed)
Memory boxes
2468intModel answer (for the teacher)
n = 2468
print(n % 10)3.4 n = 4729 (always 4 digits). Print the sum of its digits using // and %.
Output
(nothing is printed)
Memory boxes
4729intModel answer (for the teacher)
n = 4729
a = n // 1000
b = n // 100 % 10
c = n // 10 % 10
d = n % 10
print(a + b + c + d)3.5 days = 1000. Print how many whole years (365 days) and days that is, like: 2 years 270 days
Output
(nothing is printed)
Memory boxes
1000intModel answer (for the teacher)
days = 1000
print(days // 365, "years", days % 365, "days")Part 4 of 4 · learn, see, practise
Neat printing with f-strings
An f-string has f before the quote; variables go inside curly brackets and are filled in: f"{name} is {age}".
You can do maths inside the brackets: f"Next year: {age + 1}".
Output
Kabir is 12 years old. Next year Kabir will be 13.
Memory boxes
'Kabir'strage12intNo commas and no extra spaces: the sentence reads exactly as written.
Practise it
Start with the warm-up and go as far as you can. The stretch questions are meant to be hard.
4.1 Print exactly: Ravi is 12 years old. using an f-string and the variables.
Output
(nothing is printed)
Memory boxes
'Ravi'strage12intModel answer (for the teacher)
name = "Ravi"
age = 12
print(f"{name} is {age} years old.")4.2 Print: A 8 by 5 rectangle has area 40. (all three numbers from the variables)
Output
(nothing is printed)
Memory boxes
8intw5intModel answer (for the teacher)
l = 8
w = 5
print(f"A {l} by {w} rectangle has area {l * w}.")4.3 price = 250 and off = 20 (percent). Print Sale price: and the new price, worked out inside the f-string.
Output
(nothing is printed)
Memory boxes
250intoff20intModel answer (for the teacher)
price = 250
off = 20
print(f"Sale price: {price * (100 - off) / 100}")Watch out
Common mistakes
Using a name before making it
print(score) before score = 0 stops with a NameError.
Quotes around a variable name
print("name") prints the word name, not the value.
Forgetting the f
"{name} is here" prints the curly brackets. The f turns on the filling-in.
Class activity 1 of 3
The shop bill
Work out a bill for 2 pencils, 3 notebooks and 1 eraser, a discount of one tenth of the total (whole rupees), and what is left to pay. Print exactly three lines: Total: …, Discount: … and To pay: …. It must still be right if a price changes.
- Work out total = 2 pencils + 3 notebooks + 1 eraser, using the price variables.
- Work out discount = total // 10.
- Work out pay = total - discount.
- Print the three lines with f-strings.
Output
(nothing is printed)
Memory boxes
12intnotebook45interaser8inttotal0intHint
total = 2 * pencil + 3 * notebook + eraser
Model answer (for the teacher)
pencil = 12
notebook = 45
eraser = 8
total = 2 * pencil + 3 * notebook + eraser
discount = total // 10
pay = total - discount
print(f"Total: {total}")
print(f"Discount: {discount}")
print(f"To pay: {pay}")Class activity 2 of 3
Time converter
seconds = 3725. Print one line: 1 hours 2 minutes 5 seconds. It must work for any number of seconds.
- hours = seconds // 3600 (there are 3600 seconds in an hour).
- rest = seconds % 3600 (seconds left after the whole hours).
- minutes = rest // 60 and secs = rest % 60.
- Print the line with an f-string.
Output
(nothing is printed)
Memory boxes
3725intHint
3725 // 3600 is 1, and 3725 % 3600 is 125.
Model answer (for the teacher)
seconds = 3725
hours = seconds // 3600
rest = seconds % 3600
minutes = rest // 60
secs = rest % 60
print(f"{hours} hours {minutes} minutes {secs} seconds")Class activity 3 of 3
Report card
Three test marks out of 100 are given. Print exactly: Total: …, Average: … and Percent: … (the percentage of 300). It must work for any marks.
- total = m1 + m2 + m3.
- average = total / 3.
- percent = total / 300 * 100.
- Print three lines with f-strings.
Output
(nothing is printed)
Memory boxes
78intm292intm385intHint
The average and percent use / so they show .0 at the end.
Model answer (for the teacher)
m1 = 78
m2 = 92
m3 = 85
total = m1 + m2 + m3
average = total / 3
percent = total / 300 * 100
print(f"Total: {total}")
print(f"Average: {average}")
print(f"Percent: {percent}")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
Pocket money planner
Plan your savings with variables. Change the numbers at the top to your own and finish the calculations.
What to make: A program that prints at least four lines about your plan, all worked out from the variables at the top.
Stretch: Add a birthday gift of money and include it in the plan.
How it is marked
| Look for | Done well when |
|---|---|
| Variables | All numbers live in variables at the top |
| Correct maths | Savings and weeks are right |
| f-strings | Every result is a clear sentence |
| Changeable | Changing the top numbers changes every answer |
Starter code to take home
Press Copy and paste it into the editor at home, or work on it right here.
Output
I save 60 a week.
Memory boxes
150intspend90intitem'football'strprice700intsave60intHomework
Practise at home
Each one checks itself. Or print the practice sheet.
1. length = 12 and width = 5: print the area and the perimeter of the rectangle on two lines.
Output
(nothing is printed)
Memory boxes
12intwidth5int2. seconds = 500. Print like: 8 minutes 20 seconds
Output
(nothing is printed)
Memory boxes
500int3. n = 357 (3 digits). Print the number with its digits reversed (753), worked out with // and %.
Output
(nothing is printed)
Memory boxes
357intFor 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 | Sticky-note score game. | Track the value. |
| 4–12 min | Making a variable | Point at the memory boxes, then practice. | Practise to the square task. |
| 12–19 min | Changing a variable | Predict before running. | Do the swap stretch. |
| 19–29 min | Operators | Share sweets to explain // and %. | Digit-sum stretch. |
| 29–35 min | f-strings | Compare comma print and f-string. | Sale price stretch. |
| 35–43 min | Shop bill | Show what the extra checks test. | Pass every check. |
| 43–50 min | Time converter | Draw 3725 as hours, minutes, seconds. | Pass all four checks. |
| 50–56 min | Report card | Set as homework if short of time. | Build it. |
| 56–59 min | Quiz | Run the quiz. | Answer and read why. |
| 59–60 min | Set the project | Open the planner starter. | Put in their numbers. |
Questions to ask
- What does = do in Python?
- What is the difference between / and //?
- Why use variables instead of typing the numbers into the sum?
If it feels hard
Use real sticky notes for every variable and redraw them after each line.
If it feels easy
Ask for the digits of a 4-digit number printed in reverse order, separated by spaces.
FAQ
Variables: boxes that remember: questions
What is a variable in Python?
A name that holds a value, like a labelled box. Create it with =, such as score = 0, and replace the value any time.
What is the difference between / and // in Python?
/ always gives a decimal (7 / 2 is 3.5); // gives the whole-number part (3) and % the remainder (1).
What is an f-string?
A string with f in front where values in curly brackets are filled in, such as f"{name} is {age}".
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