All lessons

Lists & loops · step 15 of 22

Lab: the shopping cart

Sign in if you want this lab saved to your progress.

Total the cart, then discount it

An online shop totals a basket and applies a promotion. This lab puts loops, lists and conditions together.

Given for you: prices (the price of every item) and discount_percent

Build:

  • item_count — how many items are in the cart
  • total — the sum of every price
  • final_total — the total after the discount, but only when the total is over 50

Print: the item count, the total, then the final total (round the money to 2 decimals).

The autograder reruns your program with a small cart, so the discount rule has to be a real condition — not just a subtraction.

Build it

Fill in the code, then run it. Every check has to pass for the lab to count.

lab-shopping-cart.py

Given for you

prices = [12.5, 30, 8.25, 4.99]
discount_percent = 10