Bug(?) in It's Not All Animals and Fruits


#1

https://www.codecademy.com/courses/learn-python/lessons/introduction-to-classes/exercises/its-not-all-animals-and-fruits

I’m pretty sure there’s some sort of bug in this exercise that’s not letting me do it properly. Firstly I kept on getting the error "9/script.py has been moved. This will cause problems with this exercise, please move 9/script.py back to its original location, or reset your files”. I managed to get rid of it by resetting the code, and reentering my code in exercise 9.

However now the stuff in the console is contradictory to what the lesson explanation says should be in the console. Please look below as to what is in my console. Note that this is actually not what I wrote for the previous exercise but seems to be some sort of default solution.

In the lesson description it says “However, classes and objects are often used to model real-world objects. The code in the editor is a more realistic demonstration of the kind of classes and objects you might find in commercial software. Here we have a basic ShoppingCart class for creating shopping cart objects for website customers; though basic, it’s similar to what you’d see in a real program.”

As evidenced below this is clearly not what’s in the console. How can I solve this problem? Do I really need to start the whole classes section from the beginning again?



class Animal(object):
  """Makes cute animals."""
  is_alive = True
  health = "good"
  def __init__(self, name, age):
    self.name = name
    self.age = age
  # Add your method here!
  def description(self):
    print self.name
    print self.age
    
hippo = Animal('Anderson', 36)
sloth = Animal('Dale', 15)
ocelot = Animal('Fuzzy', 7)

print hippo.health
print sloth.health
print ocelot.health



#2

Hi @kizmoz,

Yes, it seems that there is a bug in the ShoppingCart, along with a hippo, a sloth, and an ocelot, which is not very good for business.

Try this as the initial code, and then proceed according to the instructions …

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."

Let us know whether this works.


#3

Hi @appylpye, thanks for the initial code! It seems to have worked for lesson 10 — here’s to hoping something doesn’t crop up again in a later exercise.


#4