Tutorpip← About this lessonOpen the sheet →Download PDF
Ages 10+ · Coding · Python
Numbers and maths in Python
print(2 + 3 * 4)• 3 * 4 goes first• then the 2 is added• the screen shows 14print((2 + 3) * 4)• brackets go first• 2 + 3 makes 5• then 5 * 4• the screen shows 20
Same numbers, different brackets.
The big ideaPython is a calculator. It multiplies before it adds, and brackets go first.

How it works

Python is a calculator. Plus adds, minus takes away, a star multiplies and a slash divides.

Python multiplies before it adds. That is called the order of operations.

Brackets tell Python to work that part out first.

A slash always gives a decimal, even when the answer is a whole number, so 8 / 2 shows 4.0.

Four Python lines012345652 + 339 - 662 * 315 - 4
What each line makes. Each bar is the number the line shows.

Example 1: Multiply first

  1. Zara types print(2 + 3 * 4). Leo works left to right and says twenty.
  2. Python does the star first: 3 * 4 = 12.
  3. Then it adds the two: 2 + 12 = 14.
  4. The screen shows 14, and Python was right all along.

Example 2: Brackets first

  1. Zara puts brackets round the first part: print((2 + 3) * 4).
  2. Brackets go first: 2 + 3 = 5.
  3. Then Python multiplies: 5 * 4 = 20.
  4. The screen shows 20.

Example 3: Take away and multiply

  1. The line is print(9 - 3 * 2).
  2. The star goes first: 3 * 2 = 6.
  3. Then Python takes away: 9 - 6 = 3.
  4. The screen shows 3.

Example 4: A slash

  1. Bo asks how to share eight cupcakes between two plates, so Zara types print(8 / 2).
  2. Eight shared between two plates is four each.
  3. A slash always gives a decimal, so the screen shows 4.0.

Example 5: A mix-up to fix

  1. The line print(3 x 4) does not work, because Python multiplies with a star, not an x.
  2. The mix-up to fix: print(3 * 4).
  3. Now the screen shows 12.

Words to know

order of operations
Which part of a sum Python works out first.
brackets
Make Python work that part out first.
star
The sign that multiplies.
slash
The sign that divides. It always shows a decimal.

Watch out

Try it

  1. What does print(10 - 4) show?
  2. What does print(2 + 3 * 4) show?
  3. What does print((2 + 3) * 4) show?
  4. What does print(8 / 2) show?
  5. True or false: print(3 x 4) works in Python.
Answers: 1. 6 · 2. 14 · 3. 20 · 4. 4.0 · 5. False
Try at homeWith a grown-up, write three sums on paper using plus, minus and a star, like two plus three times four. Say which part Python would work out first, then check with a real calculator. Add brackets to one sum and see if the answer changes.
For grown-upsWrite three sums on paper using plus, minus and a star, like two plus three times four. Ask which part Python would work out first, then check with a real calculator. Add brackets to one sum and see what changes.
Open these notes on screenScan the code, or go to tutorpip.com.