17. Instantiate an Object - doesn't recognise instance of Triangle cla ss


Please somebody tell me what's wrong with this. It keeps saying "Did you create an instance of Triangle called my_triangle?" As far as I can see, I have, correctly. I don't see what the problem is.


can you copy paste your code to the forum so we can run it?


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


could you explain what you do here:

        angle1 = self.angle1
        angle2 = self.angle2
        angle3 = self.angle3


Ah, okay, didn't realise the syntax only worked the other way around as I didn't get an error message when I wrote it that way in lessons 15 and 16 and it went through fine then. Have reversed the syntax and now it works fine for 17. Thank you!


you do understand what this syntax does, right? It makes your instance variable accessible through self, of course this only works one way


Yeah thinking about it properly I understand the concept, I just hadn't realised I'd made a mistake in the first place, so didn't think to think through the logic of it. I understand now, thanks.