Keep a remainder
Quick review (2 minutes)
You have a stack of 38 postcards and display sleeves that hold six cards each.
The total is how many items you start with. It can be any whole number from zero up. The group size is how many items fit in one full group. It can be any whole number from one up. Here, whole numbers are the counts 0, 1, 2 and so on.
Put the total on the left and the group size on the right. With // between them, Python gives the number of full groups. With % between them, it gives the remainder. The remainder is smaller than the group size. When it is zero, the full groups use all the items.
Write down the total and the group size.
Use
//between those numbers to find the number of full groups.Use
%between the same numbers to find the remainder.Multiply the group count by the group size and add the remainder. Check that you get the total and that the remainder is smaller than one full group.
When you type the program,
cards = 38gives the namecardsthe value 38. The linecards_per_sleeve = 6gives the group size its own name, with underscores between the words.
If you catch yourself reading % as “percent,” read 38 % 6 aloud as “How many cards are left?” Its answer counts two loose cards. If you swap the two results, you get two full sleeves and six loose cards. Six loose cards would fill one more sleeve, so the swap fails the remainder check.
1 In plain words
You have a stack of 38 postcards and display sleeves that hold six cards each. Fill as many sleeves as you can. The number of full sleeves is your group count. The number of loose cards is your remainder.
In Python 3.13, read 38 // 6 as “How many full sleeves?” and 38 % 6 as “How many cards stay loose?” Remember // for full groups and % for leftovers. To look them up, find floor division and remainder in the Python tutorial’s Numbers section.
2 Picture it
Six sleeves each contain six postcard marks. Two more marks sit outside the sleeves. The 36 packed cards and two loose cards account for all 38.
3 Why
Six full sleeves use 36 cards. Adding the two loose cards gives the whole stack again. On paper, write 6 * 6 + 2 = 38. Read * as “times,” + as “plus” and = as “equals.”
Two is smaller than six. If six or more cards were loose, you could fill another sleeve.
4 The rule
The total is how many items you start with.
It can be any whole number from zero up. The group size is how many items fit in one full group. It can be any whole number from one up. Here, whole numbers are the counts 0, 1, 2 and so on.
Put the total on the left and the group size on the right. With // between them, Python gives the number of full groups. With % between them, it gives the remainder. The remainder is smaller than the group size. When it is zero, the full groups use all the items.
5 How
- Write down the total and the group size.
- Use
//between those numbers to find the number of full groups. - Use
%between the same numbers to find the remainder. - Multiply the group count by the group size and add the remainder. Check that you get the total and that the remainder is smaller than one full group.
- When you type the program,
cards = 38gives the namecardsthe value 38. The linecards_per_sleeve = 6gives the group size its own name, with underscores between the words.
6 Worked example
Pack 38 postcards
cards = 38
cards_per_sleeve = 6
print(cards // cards_per_sleeve)
print(cards % cards_per_sleeve)
Standard input
Empty
Standard output
6
2
Save the code as postcards.py and run the file. Count full sleeves on the first output line and loose cards on the second. As a second check, subtract 6 repeatedly from 38 to reach 32, 26, 20, 14, 8 and 2.
Trace
| Instruction | Value or output | Explanation |
|---|---|---|
cards = 38 | 38 | Give the name cards the postcard count. |
cards_per_sleeve = 6 | 6 | Save the capacity of one sleeve. |
cards // cards_per_sleeve | 6 | Six full sleeves use 36 cards. A seventh would require 42. |
cards % cards_per_sleeve | 2 | Two cards remain. Six groups of six and two loose cards account for all 38 cards. |
7 The trap
If you catch yourself reading % as “percent,” read 38 % 6 aloud as “How many cards are left?” Its answer counts two loose cards. If you swap the two results, you get two full sleeves and six loose cards. Six loose cards would fill one more sleeve, so the swap fails the remainder check.
Quick checks
Quick check 1 of 2
You have 26 gift tags. Each pocket holds 8. What do 26 // 8 and 26 % 8 give? Label each answer.
Show the steps and the answer
26 // 8 gives 3 full pockets. 26 % 8 gives 2 loose tags.
Why: Three pockets use 24 tags. The 2 left cannot fill a pocket of 8.
Source: Python Software Foundation, Python 3.13 Tutorial, Numbers
Quick check 2 of 2
A greenhouse has 319 plant tags. Each tray fits 29 tags. Predict the outputs of 319 // 29 and 319 % 29. What do they tell you?
Show the steps and the answer
319 // 29 gives 11 full trays and 319 % 29 gives 0 loose tags.
Why: Eleven trays of 29 use all 319 tags.
Source: Python Software Foundation, Python 3.13 Tutorial, Numbers
Sources
- Python 3.13 Tutorial, Numbers. Python Software Foundation. Python Software Foundation License Version 2. Read 26 Nov 2026.