Drill

ProblemsPython › billing

Early payment discount

mediumbillingPython

A vendor rewards early payment: the further ahead the payment, the larger the discount off the subtotal.

early_discount(subtotal: int, days_early: int) → int

Solve it in the editor →

Where you start

def early_discount(subtotal: int, days_early: int) -> int:
    

Worked examples

CallResult
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

The same problem in another language

More billing problems in Python