Instantiate an object HELP


I do not understand why my code is not working. I suspect it is because of me not creating an "instance".
Below is my code.

class Triangle(object):
number_of_sides = 3
def init(self, angle1, angle2, angle3):
self.angle1 = angle1
self.angle2 = angle2
self.angle3 = angle3
def check_angles(self):
if self.angle1 + self.angle2 + self.angle3 == 180:
return True
return False

And the console returns this error:
Oops, try again. Did you create an instance of Triangle called my_triangle?

someone please help!


your suspension is right. You did not create a class instance, what is the struggle with creating a class instance?


I don't honestly understand myself. I still don't fully get the instance bit.
instance = Class(args) is shown in the example.
but i don't get what is meant to go into the args spot. Is it the triangle or my_triangle?


just like with normal functions:

def example(parameter1, parameter2):
    # function content

example("argument1", "argument2")

we supply arguments at function call to satisfy the function parameters

__init__() is known as a magic method, the magic bit here is that init is automatically called when you create a class instance

so, we need to supply arguments to satisfy our angle1, angle2 and angle3 parameters of init method.


Thanks! Now I understand!


I did it and I completed python! Woo Hoo!


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