Concepts / Working with Even and Odd Numbers

Working with Even and Odd Numbers

If a divides evenly by b, the remainder is 0.

  • Programming

The Leftover in a Division

When you divide objects into equal groups, the division may leave some objects ungrouped. For example, 7 apples can make 2 complete groups of 3, with 1 apple left over. The modulus operator, written as %, gives you that leftover amount. It does not give you the number of complete groups.

7 applesstarting amount2 groups2 complete groups of 317 % 31 appleleftovermake groups of 3after groupingreported by %
How do complete groups and the leftover determine the result of 7 % 3?
Key point

For 7 % 3, the dividend is 7 and the divisor is 3. The divisor tells us the group size, and the result is the amount left after making as many complete groups as possible.

Reading Modulus Expressions

In Python, the syntax is a % b. The value a is the dividend, and b is the divisor. The expression asks: after dividing a by b, what amount remains? If a divides evenly by b, the remainder is 0. For a positive divisor, the result is between 0 and b - 1.

ExpressionWhat it reportsMeaning for 7 divided by 3
7 // 3Complete groups2 complete groups
7 % 3Leftover amount1 left over
7 / 3Decimal division resultThe decimal result of the division

Different division operators extract different information from the same division.

Predicting Remainders

What do you think happens?

What is the remainder in each expression: 5 % 8, 8 % 5, and 10 % 5?

  • 5, 3, 0

  • 0, 3, 5

  • 1, 1, 2

Reveal answer
Answer:

5, 3, 0

In 5 % 8, the dividend is smaller than the divisor, so no complete group of 8 can be made and all 5 remain. In 8 % 5, one group of 5 leaves 3. In 10 % 5, the division is even, so the remainder is 0.

Worked example

Finding the remainder

Determine the results of 7 % 3, 10 % 4, 12 % 6, and 5 % 8.

  1. 1
    7 % 3

    Two complete groups of 3 use 6, leaving 1.

  2. 2
    10 % 4

    Two complete groups of 4 use 8, leaving 2.

  3. 3
    12 % 6

    Two complete groups of 6 use all 12, leaving 0.

  4. 4
    5 % 8

    The dividend 5 is smaller than the divisor 8, so no complete group of 8 can be made. The entire amount left over is 5.

Result

7 % 3 is 1, 10 % 4 is 2, 12 % 6 is 0, and 5 % 8 is 5.

7 % 3remainder 110 % 4remainder 212 % 6remainder 05 % 8remainder 5
How do different integer pairs produce different remainders?

Even and Odd Checks

Dividing by 2 creates a simple pattern. An even number divides evenly by 2, so number % 2 is 0. An odd number leaves 1 after division by 2, so number % 2 is 1. A program can use this remainder check to distinguish the two patterns.

numberdivide by 2number % 2remainderEvenremainder 0Oddremainder 1%equals 0equals 1
How does checking whether number % 2 equals 0 or 1 distinguish even numbers from odd numbers?
NumberRemainder from number % 2Pattern
40Even
51Odd
80Even
91Odd

The remainder from division by 2 identifies the even-or-odd pattern.

Repeating Modulus Patterns

Using the same divisor on an increasing sequence creates a repeating cycle of remainders. With a divisor of 3, the cycle is 0, 1, 2, 0, 1, 2, and so on. The remainders never exceed 2, which is one less than the divisor.

0remainder1remainder2remaindernext numbernext numbercycle repeats
How do remainders repeat when increasing numbers are divided by 3?
  • Detecting even and odd numbers.
  • Checking whether a number is divisible by another number.
  • Distributing items into repeating groups or buckets.
  • Calculating positions in circular structures such as clocks or calendars.

Mistakes with Remainders

  • Common mistake

    Treating % as the number of complete groups.

    What it looks like

    Interpreting 7 % 3 as 2 because two complete groups of 3 fit into 7.

    Why it fails

    The value 2 describes the complete groups, not the leftover.

    Do this instead

    Use 7 // 3 for the complete groups and 7 % 3 for the leftover, which is 1.

  • Common mistake

    Assuming a smaller dividend must produce a remainder of 0.

    What it looks like

    Expecting 5 % 8 to be 0.

    Why it fails

    No complete group of 8 fits into 5, so all 5 remain.

    Do this instead

    When the dividend is smaller than the divisor, the dividend is the leftover in this case: 5 % 8 is 5.

  • Common mistake

    Confusing a remainder of 0 with a remainder of 1 when checking parity.

    What it looks like

    Calling a number even when number % 2 is 1.

    Why it fails

    A remainder of 0 means division by 2 is exact; a remainder of 1 indicates the odd pattern.

    Do this instead

    Check for 0 to identify even numbers and 1 to identify odd numbers.

Practice with Modulus

MEDIUM

Predict the result of each expression before calculating it: 14 % 4, 18 % 6, 3 % 7, and 11 % 2. Then identify which of the numbers 14, 18, 3, and 11 follow the even pattern when checked with % 2.

Hints
  • Find the largest number of complete divisor-sized groups first.
  • The remainder is what is left after those complete groups.
  • For the even-or-odd check, compare number % 2 with 0 and 1.
  1. 1
    Identify the dividend and divisor in a % b.
  2. 2
    Determine how many complete groups of b fit into a.
  3. 3
    Find the amount left after those groups.
  4. 4
    Use that leftover as the modulus result.
  5. 5
    For an even-or-odd check, divide by 2 with % and inspect whether the result is 0 or 1.

Key Takeaways

  • The modulus operator % returns the remainder left after one integer is divided by another.
  • In a % b, a is the dividend and b is the divisor.
  • A remainder of 0 means the division is even; with division by 2, a remainder of 1 identifies the odd pattern.
  • Modulus results follow repeating cycles, which makes them useful for divisibility, grouping, circular positions, and pattern detection.
  • Do not confuse modulus with floor division: // reports complete groups, while % reports the leftover.

Related concepts

More concepts starting with W