Free lab Real Python 3. Zero installs. Your code stays in this browser. Open the playground

Numbers & Math

10 min 20 XP
Study loop Read Predict Run Tweak Prove Review
Lesson 3 of 7 · View course roadmap
Step 1

Learn the idea

Python is a superb calculator. The core operators:

  • + - * /: the classics (/ always gives a float)
  • //: floor division, which drops the remainder, so 7 // 2 → 3
  • %: modulo (the remainder), so 7 % 2 → 1
  • **: power, so 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.3 is False (it's 0.30000000000000004). Use round() for display and the decimal module for money.
  • Integer division habits from other languages: in Python, 7 / 2 is 3.5, never 3. Use // when you want the floor.
  • Operator precedence: 2 + 3 * 4 is 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.

Step 2

Watch how it runs line by line


        

Press play to watch Python execute this code, one line at a time.

Step 3

Try it yourself

Blank · autosaved

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”.

PYexample.py
⌘ + Enter to run
Output appears here…
Step 4

Pass the challenge +20 XP

Blank · autosaved

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.

Target output
84
2
PYchallenge.py
Run your code to check it…
Step 5

Check your understanding

1. What does 10 % 3 evaluate to?
2. What is the result type of 8 / 2?
Last step

Your notes (saved on this device)

Tip: use ← and → to move between lessons, ⌘K to search everything.

Your next ten minutes

Write Python that does something useful.

Start free. No install, no card, no passive video marathon.

Start learning free → Explore the path