Drill

ProblemsPython › billing

How much is still owed

easybillingPython

Compare the amount due against a list of payments already received and return the shortfall.

balance_shortfall(due: int, payments: list<int>) → int

Solve it in the editor →

Where you start

def balance_shortfall(due: int, payments: list[int]) -> int:
    

Worked examples

CallResult
balance_shortfall(10000, [3000, 4000])3000
balance_shortfall(5000, [5000])0
balance_shortfall(5000, [6000])0
balance_shortfall(1000, [])1000

Hint

Sum the payments and subtract from due.

Reference solution in Python
def balance_shortfall(due: int, payments: list[int]) -> int:
    return max(0, due - sum(payments))

The same problem in another language

More billing problems in Python