What does this parcel cost to send
A courier prices every parcel as: the first five kilograms cost 300 (minor units) and each further kilogram adds 60.
- A parcel at or under five kilograms always costs 300.
- Every whole kilogram over five adds 60; there are no fractions here.
- A parcel cannot weigh negative kilograms: return 0 for bad input.
parcel_cost(weight: int) → int
Where you start
def parcel_cost(weight: int) -> int:
Worked examples
| Call | Result |
|---|---|
parcel_cost(3) | 300 |
parcel_cost(5) | 300 |
parcel_cost(6) | 360 |
parcel_cost(10) | 600 |
Hint
Subtract the free five, multiply what is left, and add the base.
Reference solution in Python
def parcel_cost(weight: int) -> int:
if weight < 0:
return 0
return 300 + max(0, weight - 5) * 60