Integer Division and Remainder
Write pack_boxes(items, box_size) that returns two values: how many full boxes you can fill, and how many items are left over.
With 17 items and boxes of 5, you fill 3 boxes and have 2 items left, so it returns (3, 2).
Examples
17 items in boxes of 5 fills 3 boxes with 2 left over
- Input
- pack_boxes(17, 5)
- Output
- [3, 2]
An exact fit leaves nothing over
- Input
- pack_boxes(20, 5)
- Output
- [4, 0]
Fewer items than a box means 0 full boxes and everything left
- Input
- pack_boxes(3, 5)
- Output
- [0, 3]
Hints
Hint 1
The remainder operator gives what is left after the division.
Hint 2
Watch for this: used true division.
Requirements
: total number of items (a whole number)
box_size: how many items fit in one box (a whole number)Return a tuple (full_boxes, leftover).
Constraints
Standard library only, no imports required
Time limit: 200 ms, Memory: 64 MB
Where this shows up
3 employers weight this skill
2 frontier labs, 1 AI product company. Top match scores 80.
def pack_boxes(items, box_size):
"""
Work out full boxes and leftovers.
Args:
items: total number of items (a whole number)
box_size: how many items fit in one box (a whole number)
Returns:
A tuple (full_boxes, leftover).
"""
# YOUR CODE HERE
pass