×

python · level 1 · unit 3 · lesson 2

  1. meet it
  2. guess first
  3. your turn
  4. fix it
  5. nailed it

Tap a green word if you get lost.

meet it

Python is a calculator that never gets tired.

Each maths symbol is an . + adds, - takes away, * multiplies (a star, not an x) and / divides. Python works out the answer for you.

Dividing can leave bits. 7 / 2 gives 3.5, a : a number with a dot in it. Sharing 7 slices between 2? 7 // 2 gives 3 whole slices each, and 7 % 2 gives the 1 left over.

Like on paper, * and / happen before + and -. Brackets beat them all, so wrap the part you want worked out first.

print(7 / 2)
print(7 // 2)
print(7 % 2)
print(2 + 3 * 4)
print((2 + 3) * 4)

Read % as "left over", not "percent".