Price per unit
A bulk bin lists a total for a quantity of identical items. What does a single unit cost?
- Price per unit is total ÷ quantity, rounded down to whole minor units.
- A quantity of zero or less has no per-unit price: return 0.
price_per_unit(total_minor: int, quantity: int) → int
Where you start
def price_per_unit(total_minor: int, quantity: int) -> int:
Worked examples
| Call | Result |
|---|---|
price_per_unit(1000, 4) | 250 |
price_per_unit(1000, 3) | 333 |
price_per_unit(100, 10) | 10 |
price_per_unit(0, 5) | 0 |
Hint
Divide and drop the remainder.
Reference solution in Python
def price_per_unit(total_minor: int, quantity: int) -> int:
if quantity <= 0:
return 0
return total_minor // quantity