Instantiating Objects


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

my_triangle = Triangle(90, 30, 60)
print my_triangle.number_of_sides
print my_triangle.check_angles()

Gives error "'int' object has no attribute 'self'"


the issue comes from these lines angle# are int types. So when you write angle#.self, the interpreter thinks you are looking for an attribute associated with int types named self but it does not exist.

It should be the other way around