10/18 Please help, this makes no sense!


#1



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


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


I feel like my code should work, as I read other topics and they seemed like mine at the finished product.


Replace this line with your code. 
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."
    my_cart = ShoppingCart("Eric")
    my_cart.add_item("Ukelele", 10)


#2

your not making an object from ShoppingCart, though,
check your indentations, see what's inside a method


#3

Thank you so much, for clearing it up for me!


#4

You just need to outdent you code to take it outside the class ShoppingCart, then you will be creating your own instance of ShoppingCart and populating it.


#5

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