Will this fit in the bay
Goods-in scans a pallet and asks whether the bay it is headed for can take it.
- A missing item, or one with a quantity of zero or less, never fits.
- What is already there plus what is arriving must not exceed capacity.
- Filling the bay exactly is fine.
can_store(item: Item?, on_hand: int, capacity: int) → bool
Where you start
def can_store(item: Item | None, on_hand: int, capacity: int) -> bool:
Worked examples
| Call | Result |
|---|---|
can_store(Item(name="bolt", qty=3), 0, 100) | True |
can_store(Item(name="bolt", qty=5), 10, 15) | True |
can_store(Item(name="bolt", qty=5), 10, 12) | False |
can_store(Item(name="bolt", qty=0), 0, 100) | False |
Hint
Two guards, then one comparison. Watch the boundary: equal to capacity still fits.
Reference solution in Python
def can_store(item: Item | None, on_hand: int, capacity: int) -> bool:
if item is None or item.qty <= 0:
return False
return on_hand + item.qty <= capacity