add a method description,to your Animal class.using two separate print statements,it should print out the name and age of the animal it's called on.then,create an instance of Animal,hippo(with whatever name and age you like),and can its description method.
Hint:
your method should look something like this:
def description(self):
print self.name
print self.age
after that all you need to do is create a hippo and call its description method with hippo.description()
remember to pass self as an argument to description.otherwise,printing self.name and self.age won't work,since python won't know which self (that is,which object) you're talking about.
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("chad",7)
hippo.description()
两个def要对齐,不然就出错。
using two separate print ,看了帮助才知道正确的写法