Drill

ProblemsPython › billing

Prorate an annual subscription refund

mediumbillingPython

When a subscriber cancels early, the unused portion of the annual fee is refunded proportionally.

prorate_refund(annual_amount: int, months_used: int) → int

Solve it in the editor →

Where you start

def prorate_refund(annual_amount: int, months_used: int) -> int:
    

Worked examples

CallResult
prorate_refund(12000, 0)12000
prorate_refund(12000, 12)0
prorate_refund(12000, 3)9000
prorate_refund(10000, 5)5833

Hint

Clamp first, then multiply before dividing.

Reference solution in Python
def prorate_refund(annual_amount: int, months_used: int) -> int:
    m = max(0, min(12, months_used))
    return annual_amount * (12 - m) // 12

The same problem in another language

More billing problems in Python