LESSON 03 / 05

Maths & Operators

+ - * / plus Python’s special // (floor division), % (remainder) and ** (power) — and the round() and math tools.

🎓Beginnerlevel
⏱️30 minto finish
✏️2activities

📂 First Steps in Python🏷️ Python basics

🎯 By the end of this lesson you can…

  • Use all arithmetic operators including // % **
  • Use += style shortcuts
  • Round and use the math module
Python operators
OperatorMeaningExampleResult
/divide7 / 23.5
//floor divide7 // 23
%remainder7 % 21
**power2 ** 101024
+=add tox += 5x grows by 5
🐍 Python maths.py 👆 Tap a line to explain it
1print(17 / 5)2print(17 // 5)3print(17 % 5)4print(2 ** 10)5balance = 1006balance -= 307balance *= 28print(balance)9print(round(3.14159, 2))
🐍 Python math-module.py 👆 Tap a line to explain it
1import math2print(math.sqrt(144))3print(math.ceil(2.1), math.floor(2.9))4print(math.pi)
🔮 What will this display?
What does this print?
1print(20 // 6, 20 % 6)
🛠️ Minutes to hours

Read a number of minutes and print it as H hours M minutes, e.g. 150 → 2 hours 30 minutes.

📌 Key takeaways

  • / always gives a float; // gives whole-number division.
  • % is the remainder; ** is power.
  • round(x, 2) rounds to 2 decimal places.

Finished reading & practising?

Saved in this browser. Create a free account to keep it forever.