🎯 By the end of this lesson you can…
- Use all arithmetic operators including // % **
- Use += style shortcuts
- Round and use the math module
| Operator | Meaning | Example | Result |
|---|---|---|---|
/ | divide | 7 / 2 | 3.5 |
// | floor divide | 7 // 2 | 3 |
% | remainder | 7 % 2 | 1 |
** | power | 2 ** 10 | 1024 |
+= | add to | x += 5 | x 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.