Command Palette

Search for a command to run...

Hectal
Phase 8: Object-Oriented Python
Python · Exercise 2 of 6 PreviousNext
Beginner

Fix the shared list

The class below shares one list between all carts. Fix Cart so every cart has its own items list.

add(item) appends an item and count() returns how many items the cart holds.

What Check tests

  1. A new cart is empty
  2. add increases the count
  3. Two carts do not share items

Stuck? One hint at a time

The solution unlocks after your first Check. Try first: that is where the learning happens.

main.py
Sign in to run your code.

Output

Press Run to see what your program prints.