runtime
38 / 500
question 38 Conditional Logic · medium

Price a cart with a coupon code

A checkout accepts two coupon codes. WELCOME10 takes 10% off the subtotal. FREESHIP makes shipping free. No code (empty text) means no coupon. Any other code prints Unknown coupon: and the code, and then works like no coupon. Shipping is 5, but free when the subtotal after the discount is 50 or more. Use match for the codes, then print the discount, the shipping and the total.

First linessubtotal = 60 and coupon = "WELCOME10". Check runs your program again with other carts
PrintsDiscount: 6.0, Shipping: 0, Total: 54.0
Discountalways computed as subtotal × percent / 100, so it prints as a decimal, 0.0 with no coupon
Expected output3 lines
  1. 1Discount: 6.0
  2. 2Shipping: 0
  3. 3Total: 54.0

Loading your progress…

Price a cart with a coupon code — Python practice · Runtime