10. It's Not All Animals and Fruits



Oops, try again. Did you declare a variable called my_cart?

Traceback (most recent call last):
File "python", line 1, in
File "python", line 24, in ShoppingCart
NameError: name 'ShoppingCart' is not defined

I don't know why my code is doing this. I'm very sure I did everything correctly

class ShoppingCart(object):
    """Creates shopping cart objects
    for users of our fine website."""
    items_in_cart = {}
    def __init__(self, customer_name):
        self.customer_name = customer_name

    def add_item(self, product, price):
        """Add product to the cart."""
        if not product in self.items_in_cart:
            self.items_in_cart[product] = price
            print product + " added."
            print product + " is already in the cart."

    def remove_item(self, product):
        """Remove product from the cart."""
        if product in self.items_in_cart:
            del self.items_in_cart[product]
            print product + " removed."
            print product + " is not in the cart."          
    my_cart = ShoppingCart("Bob")


It's okay. I had to move back the my_cart


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.