Book a free demo

🐍 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.

🖨 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. Making a variable8 min
  3. Changing a variable7 min
  4. Operators10 min
  5. f-strings6 min
  6. Shop bill8 min
  7. Time converter7 min
  8. Report card6 min
  9. Quiz3 min
  10. 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.

Example: run it, then change it

Output

Riya
Riya is 11

Memory boxes

name'Riya'strage11int

Look 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.

Warm-up

1.1 The variable name is already made. Print Hello, followed by the name (use a comma).

Task 1.1

Output

(nothing is printed)

Memory boxes

name'Zara'str
Model answer (for the teacher)
name = "Zara"
print("Hello,", name)
Warm-up

1.2 Make a = 6 and b = 7 and print their product.

Task 1.2

Output

(nothing is printed)

Memory boxes

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

1.3 price = 40 and qty = 3. Print Cost: and the cost.

Task 1.3

Output

(nothing is printed)

Memory boxes

price40intqty3int
Model answer (for the teacher)
price = 40
qty = 3
print("Cost:", price * qty)
Stretch 🔥

1.4 side = 5. Print two lines: Area: … and Perimeter: … of a square with that side.

Task 1.4

Output

(nothing is printed)

Memory boxes

side5int
Model 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.

Example: run it, then change it

Output

Final score: 30

Memory boxes

score30int

The 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.

Warm-up

2.1 score starts at 0. Add 5 three times using += and print score.

Task 2.1

Output

(nothing is printed)

Memory boxes

score0int
Model answer (for the teacher)
score = 0
score += 5
score += 5
score += 5
print(score)
Core

2.2 money = 100. Spend 35, earn 20, then double what is left. Print money.

Task 2.2

Output

(nothing is printed)

Memory boxes

money100int
Model answer (for the teacher)
money = 100
money -= 35
money += 20
money *= 2
print(money)
Stretch 🔥

2.3 Swap the values of a and b, then print a and b on one line. (Hint: a third box.)

Task 2.3

Output

(nothing is printed)

Memory boxes

a1intb2int
Model 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.

Example: run it, then change it

Output

2 hours and 15 minutes
2.5
32

Memory boxes

minutes135inthours2intleft15int

135 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.

Warm-up

3.1 Print 17 // 5 on one line and 17 % 5 on the next.

Task 3.1

Output

(nothing is printed)

Memory boxes

No variables yet
Model answer (for the teacher)
print(17 // 5)
print(17 % 5)
Core

3.2 sweets = 47 are shared equally by kids = 6. Print Each: … and Left: ….

Task 3.2

Output

(nothing is printed)

Memory boxes

sweets47intkids6int
Model answer (for the teacher)
sweets = 47
kids = 6
print("Each:", sweets // kids)
print("Left:", sweets % kids)
Core

3.3 n = 2468. Print its last digit using %.

Task 3.3

Output

(nothing is printed)

Memory boxes

n2468int
Model answer (for the teacher)
n = 2468
print(n % 10)
Stretch 🔥

3.4 n = 4729 (always 4 digits). Print the sum of its digits using // and %.

Task 3.4

Output

(nothing is printed)

Memory boxes

n4729int
Model 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)
Stretch 🔥

3.5 days = 1000. Print how many whole years (365 days) and days that is, like: 2 years 270 days

Task 3.5

Output

(nothing is printed)

Memory boxes

days1000int
Model 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}".

Example: run it, then change it

Output

Kabir is 12 years old.
Next year Kabir will be 13.

Memory boxes

name'Kabir'strage12int

No 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.

Warm-up

4.1 Print exactly: Ravi is 12 years old. using an f-string and the variables.

Task 4.1

Output

(nothing is printed)

Memory boxes

name'Ravi'strage12int
Model answer (for the teacher)
name = "Ravi"
age = 12
print(f"{name} is {age} years old.")
Core

4.2 Print: A 8 by 5 rectangle has area 40. (all three numbers from the variables)

Task 4.2

Output

(nothing is printed)

Memory boxes

l8intw5int
Model answer (for the teacher)
l = 8
w = 5
print(f"A {l} by {w} rectangle has area {l * w}.")
Stretch 🔥

4.3 price = 250 and off = 20 (percent). Print Sale price: and the new price, worked out inside the f-string.

Task 4.3

Output

(nothing is printed)

Memory boxes

price250intoff20int
Model 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.

  1. Work out total = 2 pencils + 3 notebooks + 1 eraser, using the price variables.
  2. Work out discount = total // 10.
  3. Work out pay = total - discount.
  4. Print the three lines with f-strings.
Your code

Output

(nothing is printed)

Memory boxes

pencil12intnotebook45interaser8inttotal0int
Hint

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.

  1. hours = seconds // 3600 (there are 3600 seconds in an hour).
  2. rest = seconds % 3600 (seconds left after the whole hours).
  3. minutes = rest // 60 and secs = rest % 60.
  4. Print the line with an f-string.
Your code

Output

(nothing is printed)

Memory boxes

seconds3725int
Hint

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.

  1. total = m1 + m2 + m3.
  2. average = total / 3.
  3. percent = total / 300 * 100.
  4. Print three lines with f-strings.
Your code

Output

(nothing is printed)

Memory boxes

m178intm292intm385int
Hint

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.

1What does this show?
x = 5
x = x + 2
print(x)
Show the answer

7. x starts at 5, then becomes 5 + 2.

2What does this show?
print(7 // 2)
Show the answer

3. // divides and drops the remainder.

3What does this show?
print(23 % 5)
Show the answer

3. 23 = 5 × 4 + 3.

4What does this show?
print(2 ** 3)
Show the answer

8. 2 × 2 × 2.

5What does this show?
name = "Sam"
print(f"Hi {name}")
Show the answer

Hi Sam. The f-string fills in the value.

6What does this show?
a = 3
b = a
a = 10
print(b)
Show the answer

3. b got the value 3; changing a later does not change b.

7What does this show?
n = 345
print(n // 10 % 10)
Show the answer

4. 345 // 10 is 34, and 34 % 10 is 4: the tens digit.

8Which is a valid variable name?
Show the answer

my_score. No starting digit, no spaces, no -.

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 forDone well when
VariablesAll numbers live in variables at the top
Correct mathsSavings and weeks are right
f-stringsEvery result is a clear sentence
ChangeableChanging 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.

Project starter

Output

I save 60 a week.

Memory boxes

weekly150intspend90intitem'football'strprice700intsave60int

Homework

Practise at home

Each one checks itself. Or print the practice sheet.

Warm-up

1. length = 12 and width = 5: print the area and the perimeter of the rectangle on two lines.

Homework 1

Output

(nothing is printed)

Memory boxes

length12intwidth5int
Core

2. seconds = 500. Print like: 8 minutes 20 seconds

Homework 2

Output

(nothing is printed)

Memory boxes

seconds500int
Stretch 🔥

3. n = 357 (3 digits). Print the number with its digits reversed (753), worked out with // and %.

Homework 3

Output

(nothing is printed)

Memory boxes

n357int

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-upSticky-note score game.Track the value.
4–12 minMaking a variablePoint at the memory boxes, then practice.Practise to the square task.
12–19 minChanging a variablePredict before running.Do the swap stretch.
19–29 minOperatorsShare sweets to explain // and %.Digit-sum stretch.
29–35 minf-stringsCompare comma print and f-string.Sale price stretch.
35–43 minShop billShow what the extra checks test.Pass every check.
43–50 minTime converterDraw 3725 as hours, minutes, seconds.Pass all four checks.
50–56 minReport cardSet as homework if short of time.Build it.
56–59 minQuizRun the quiz.Answer and read why.
59–60 minSet the projectOpen 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

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