10: It's not all animals and fruits



Why the code isn't being executed? I have created the my_cart variable but still it is asking for one.

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

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."
    def __init__(self,ShoppingCart):
        self.ShoppingCart= ShoppingCart
        my_cart= ShoppingCart("Freddie")

How to proceed further?


when you create an instance of your object:

my_cart= ShoppingCart("Freddie")

you should do this outside your object (change the indent)

also, the add_item method requires two arguments, you only provide when one argument when calling the method


What stetim94 said is exactly right. The indent should be removed. The other thing is that the add_item method takes in two arguments: product and price. You gave in only one argument, that is, the product. You also have to give some price as an argument. Then, everything will be fine. Hope you understood :smile:


Yes. Thanks sir! Helpful indeed!