Quotes help make search much faster. Example: "Practice Makes Perfect"

Sunday, December 2, 2012

Codecademy: They're Multiplying


#sample solution


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 "My name is %s." % (self.name)
print "I'm %s years old." % (self.age)

sloth = Animal("Jim",30)
ocelot = Animal("Pam",29)
hippo = Animal("Dwight",34)
print sloth.health
print ocelot.health
print hippo.health

4 comments:

  1. You are missing hippos creation and health to this solution.

    ReplyDelete
  2. 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("babu",3)
    print hippo.description()
    print hippo.health

    sloth = Animal("sam",6)
    print sloth.health

    ocelot = Animal("ram",23)
    print ocelot.health

    for this code i am getting the error
    "Oops, try again! Did you create an Animal() called sloth?"

    can someone help me? thanks in advance

    ReplyDelete
    Replies
    1. Hello Vijaiya,

      Just checked your code and it works. Just make sure you have proper indentation.

      https://gist.github.com/nathanweis/7192730

      Delete


This is an example of scrolling text using Javascript.

Popular Posts