Numbers & Math
Lesson 3 of 7 · View course roadmap
Learn the idea
Python is a superb calculator. The core operators:
+ - * /— the classics (/always gives a float)//— floor division (drops the remainder):7 // 2→3%— modulo (the remainder):7 % 2→1**— power:2 ** 10→1024
Shorthand operators update a variable in place: score += 10 means score = score + 10.
The modulo operator is secretly one of the most useful in programming — x % 2 == 0 is the classic test for an even number.
Where you'll use this
Modulo drives real systems: 'every 15th request gets logged', hash tables, round-robin load balancing, cyclic calendars. Floor division powers pagination — page = item_index // page_size.
Common mistakes
- Floating point surprises:
0.1 + 0.2 == 0.3is False (it's 0.30000000000000004). Useround()for display and thedecimalmodule for money. - Integer division habits from other languages: in Python,
7 / 2is 3.5, never 3. Use//when you want the floor. - Operator precedence:
2 + 3 * 4is 14, not 20 — use parentheses generously.
Pro tip
Python ints have no maximum size — 2 ** 10000 just works. Also: underscores make big numbers readable: population = 8_100_000_000.
Watch how it runs — line by line
Press play to watch Python execute this code, one line at a time.
Try it yourself
The lesson example is loaded and ready — press Run, then change something and run it again. Breaking it is part of learning. Want a clean slate? Tap “New blank”.
Output appears here…
Pass the challenge +20 XP
A cinema ticket costs 12 euros. Calculate and print the cost of 7 tickets, then print the remainder when 100 is divided by 7. Expected output is 84 then 2.
84 2
Multiplication first, then use the % operator for the remainder.
ticket_price = 12 print(ticket_price * 7) print(100 % 7)
Run your code to check it…
Check your understanding
Your notes (saved on this device)
Tip: use ← and → to move between lessons, ⌘K to search everything.