Instantiate an Object


#1

In the code below, we set self.angle1 = angle1, etc... I'm curious as to why I get an error when I leave off the "self" in the if statement of check_angles (i.e. why can't we write angle1 + angle2 + angle3 == 180 instead of self.angle1 + self.angle2 + self.angle3 == 180). Shouldn't they be equivalent since we equated the 2 in the init() method and self is a parameter of check_angles? When I try it, the error I get is "In your check_angles method, make sure to check the sum of self.angle1 + self.angle2 + self.angle3." Thanks!

class Triangle(object):

def __init__(self, angle1, angle2, angle3):
    self.angle1 = angle1
    self.angle2 = angle2
    self.angle3 = angle3

number_of_sides = 3

def check_angles(self):
    if self.angle1 + self.angle2 + self.angle3 == 180:
        return True
    else:
        return False

#2

The angles are stored in the object and the way a method accesses an object is through its first parameter.

If you test the method yourself instead of leaving that to codecademy, you'll get a NameError saying that angle1 isn't defined.