A methodical approach


#1



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.description()

"""please help me in correcting this code"""

Replace this line with your code.


#2

please start using the template better, include error message and place your code at where it says (replace this line with your code), so the indent shows, and preferable the exercise url so we can quickly debug your code in the lesson

description is a function at the moment, it should be a method (nested inside the class, hint: indent)


#3

Once we create an class(our blue print), we need to create an instance before we call method on it.

read instruction.

then, create an instance of Animal, hippo (with whatever name and age you like), and call its description method.

also the description methods should be inside the Animal class (just seen formatted code).


#4

This one..
link

@javacoder32998

as mentioned by stetim, the url and error message would helps us help you better!
so pls put them with your code.


#5

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('rajat',22)
print hippo.description(self.name)
print hippo.description(self.age)

please help me to correct this code..


#6

here:

print hippo.description(self.name)
print hippo.description(self.age)

the method calls don't need arguments, self is a special parameter which doesn't need an argument. You already given your hippo a name and age when you created the instance


#7

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