8. A methodical approach


#1


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


Honestly... I do not know what to do here. I have very basic understanding of ADT, and maybe I was a little naive to think that by simply trying to use the accessor functions underneath the printed objects, that strings and values I wanted to print to the console would do so without a hitch. I am completely lost. I have read the question, but I do not know what it wants from me, or how to achieve. Can I please have a hint on how to go in the right direction?


class Animal(object):
    """Makes cute animals."""
        def __init__(self, name, age, description):
        self.name = name
        self.age = age
        self.description = description
    # Add your method here!
    
class hippo(object):
    is_alive = True
    def description(self,name,age):
        self.name = name
        self.age = age
        print self.name
        print self.age

        
hippo = Animal("Gordo", 7)

print hippo.description()


#2

There's no need creating a new class entirely for each new object, simply add the description method to the Animal class and print your hippo object afterwards. Try my code below.

class Animal(object):
    """Makes cute animals."""
    is_alive = True
    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("Happy",21)
print hippo.description

#3

hippo is described as an instance of Animal (so its type is Animal, it's not a subclass of Animal, though you haven't done that either since your hippo class does not inherit Animal in your code)


#4

It doesn't matter, but there shouldn't be a print before hippo.description


#5

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