The Seven Operators

Both languages share the same arithmetic toolkit:

+ add · - subtract · * multiply · / divide

% modulo, the remainder after division

** exponent, raise to a power

// (Python), floor division, dropping the remainder. JavaScript writes it Math.floor(a / b).

EXAMPLE
loading editor…
YOUR TURN
Your turn → Modulo (%) gives the remainder. Add two lines: one that works out how many full hands of 6 cards you can deal from 52 (// in Python, Math.floor in JavaScript), and one that uses % to find how many cards are left over.
loading editor…

Syntax has to be exact. Every quote, bracket and parenthesis needs its partner, and in Python the spaces at the start of a line count. One slip and the program won't run; the message will say where.

✦ Where modulo shows up

Even/odd checks (n % 2), rotating through drum patterns, wrapping around a clock, alternating row colors in a table. Remainders are everywhere once you see them.

Mark this lesson complete

Signed in, your progress follows you to every device.

Next: Order of Operations →
← Back