9/18 help me I don't know


#1

class Animal(object):
"""Makes cute animals."""

is_alive = True
health = "good"
def __init__(self, name, age):
    self.name = name
    self.age = age

def description(self):
    print(self.name)
    print(self.age)
    
    sloth = Animal("jinwa",23)
    ocelot = Animal("kok", 23)
    hippo = Animal("jin",22)
    
print sloth.is_alive   
print ocelot.is_alive
print hippo.is_alive

#2

@yoojinhwa,

class Animal(object):
    """Makes cute animals."""
    is_alive = True
    health = "good"

    def __init__(self, name, age):
        self.name = name
        self.age = age

    def description(self):
        print("My name is: " + self.name)
        print("My age is : " + str(self.age))
        
    def __str__(self):
        return str(self.__class__) + ": " + str(self.__dict__)
    
sloth = Animal("jinwa",23)
ocelot = Animal("kok", 23)
hippo = Animal("jin",22)
    
print sloth.is_alive   
print ocelot.is_alive
print hippo.is_alive
sloth.description()
print(sloth)

[output]

True
True
True
My name is: jinwa
My age is : 23
<class '__main__.Animal'>: {'age': 23, 'name': 'jinwa'}

#3

oops..
you

def str(self):
return str(self.class) + ": " + str(self.dict)

---> what does this mean??


#4

Hello, I have printed both the name of the animal and health and work!
print hipopotamo.nombre, hipopotamo.salud
print perezoso.nombre, perezoso.salud
print ocelote.nombre, ocelote.salud


#5

This worked for me

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("Bertha", 21)
sloth = Animal("Stan", 99)
ocelot = Animal("Ozzy", 5)
hippo.description()
print hippo.health
print sloth.health
print ocelot.health