Drill

ProblemsPython › billing

Compute the final charge on an order

easybillingPython

Combine a subtotal, an optional discount, and shipping to produce the final amount due.

final_charge(subtotal: int, discount: int, shipping: int) → int

Solve it in the editor →

Where you start

def final_charge(subtotal: int, discount: int, shipping: int) -> int:
    

Worked examples

CallResult
final_charge(5000, 500, 800)5300
final_charge(1000, 2000, 500)500
final_charge(3000, 0, 1000)4000
final_charge(0, 0, 0)0

Hint

Max(0, subtotal − discount) then add shipping.

Reference solution in Python
def final_charge(subtotal: int, discount: int, shipping: int) -> int:
    net = subtotal - discount if subtotal > discount else 0
    return net + shipping

The same problem in another language

More billing problems in Python