runtime
86 / 500
question 86 Functions · medium

Checkout crashes without a coupon

checkout_total(subtotal, coupon=None) should take 10% off when the coupon is "SAVE10", then add 5.99 shipping unless the discounted subtotal is 50 or more. With the coupon it returns a number, but a call without a coupon stops with UnboundLocalError, and some orders get free shipping they shouldn't. Fix the function.

Functioncheckout_total(subtotal, coupon=None)
Discount10% off the subtotal when coupon == "SAVE10"; any other coupon (or none) gives no discount
Shipping5.99, free when the subtotal after the discount is 50 or more
Returnsthe discounted subtotal plus shipping
Examples
callcheckout_total(80, 'SAVE10')returns72.0
callcheckout_total(30)returns35.99
callcheckout_total(120)returns120.0

Loading your progress…

Checkout crashes without a coupon — Python practice · Runtime