Early payment discount
A vendor rewards early payment: the further ahead the payment, the larger the discount off the subtotal.
- Days early >= 10 earns a 2% discount, rounded down.
- Days early >= 5 (but under 10) earns a 1% discount, rounded down.
- Under 5 days earns no discount.
- The discount is floor(subtotal × percentage / 100).
early_discount(subtotal: int, days_early: int) → int
Where you start
def early_discount(subtotal: int, days_early: int) -> int:
Worked examples
| Call | Result |
|---|---|
early_discount(10000, 10) | 200 |
early_discount(5000, 5) | 50 |
early_discount(7500, 15) | 150 |
early_discount(999, 3) | 0 |
Hint
Check the thresholds from largest to smallest.
Reference solution in Python
def early_discount(subtotal: int, days_early: int) -> int:
if days_early >= 10:
return subtotal * 2 // 100
if days_early >= 5:
return subtotal // 100
return 0