Is it just me or is this wording missleading


#1



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


The wording for the problem says Create an instance of ShoppingCart called my_cart. Initialize it with any values you like, then use the add_item method to add an item to your cart.'

So the wording of the problem suggests that we are supposed to create essentially a list of items for my_cart something like my_cart = ShoppingCart('grades', 'apples') etc. etc.

Again the wording literally says 'Create an instance of ShoppingCart called my_cart. Initialize it with any values you like' To me this literally implies exactly what I wrote above.

The instructions should say something along the lines of Create an instance of ShoppingCart called my_cart. Assign the customer name of the shopping cart and then use the add_item method to add an item to your cart.

It just isn't clear. The instructions do not match the problem and you can do better.


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('Tod')

my_cart.add_item('Toast', 12)


#2

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