$ ./guess_the_languageProblem Solving — fix the bug
Problem Solving — fix the bug · hard · #147

What is the correct fix?

class Cart:
    items = []

    def add(self, x):
        self.items.append(x)
  1. Create items in __init__
  2. Mark items as a property
  3. Rename items to _items
  4. Add @staticmethod to add
A class-level list is shared by every instance, so all carts see the same items.
Play Problem Solving ▸