What is the correct fix?
class Cart:
items = []
def add(self, x):
self.items.append(x)
- Create
itemsin__init__ - Mark
itemsas a property - Rename
itemsto_items - Add
@staticmethodto add
A class-level list is shared by every instance, so all carts see the same items.
Play Problem Solving ▸