10: It's not all animals and fruits


#1




https://www.codecademy.com/courses/python-intermediate-en-WL8e4/1/5?curriculum_id=4f89dab3d788890003000096#


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."
        else:
            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."
        else:
            print product + " is not in the cart."
    def __init__(self,ShoppingCart):
        self.ShoppingCart= ShoppingCart
        my_cart= ShoppingCart("Freddie")
        my_cart.add_item("Staf")

How to proceed further?


#2

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


#3

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:


#4

Yes. Thanks sir! Helpful indeed!


#5