All lessons
🔢

Math & Numbers

Arithmetic, math module, and operators

Reward
+40 XP

Arithmetic operators

Python supports +, -, *, /, // (floor division), % (modulo), ** (power).

print(10 + 3)   # 13
print(10 / 3)   # 3.333...
print(10 // 3)  # 3
print(10 % 3)   # 1
print(2 ** 8)   # 256

Math module

The math module provides advanced functions like sqrt, ceil, floor, factorial.

import math
print(math.ceil(4.3))   # 5
print(math.floor(4.7))  # 4
print(math.pow(2, 10))  # 1024.0

Try it yourself

Run the example below. Edit it and see what changes.

main.py
Output
Press Run to execute (Ctrl/Cmd+Enter)

Common mistakes

  • Confusing / (true division) with // (floor division).
  • Forgetting that ** is power, not ^.