Dividing and what's left
Share things out evenly and find out how many are left over. About 8 minutes.
Sharing sweets
You have 14 sweets to share among 4 friends, and nobody may get a broken sweet. Each friend gets 3, which uses up 12 sweets. Two sweets are left over.
Computers call the first part whole-number division: how many full groups fit. The leftover is called the remainder. Python writes whole-number division with two slashes, and the other languages use a single slash when both numbers are whole.
full = 14 // 4 # 3 left = 14 % 4 # 2
- groups
- 1
- left over
- 10
The first group of 4 sweets is handed out.
Hours and minutes
A clock does this all day long. You have 135 minutes, and an hour is 60 minutes. Divide 135 by 60 and you get 2 full hours. The remainder is 15, so there are 15 minutes left.
Whenever a question says "how many full ones" and "how many are left", reach for these two tools. Use the same number for both: the size of one group.
total = 135 hours = total // 60 minutes = total % 60
17 sweets are shared among 5 friends, and nobody gets a broken sweet. How many does each friend get, and how many are left over?
- A3 each, 2 left over
- B2 each, 3 left over
- C4 each, none left
Show the answer
3 each, 2 left over. 5 friends times 3 is 15, and 17 minus 15 leaves 2.
Hours and minutes
A video lasts a given number of minutes in total. Return how many full hours it lasts and how many minutes are left, as a list: hours first, then minutes.
total = 135 → [2, 15]
0 ≤ total ≤ 1,000,000