Class it up


I have a problem with compilation in this exercise.
The code is

class Triangle(object):
    number_of_sides = 3
    def __init__(self,angle1, angle2, angle3):
        Triangle.self = self
        Triangle.angle1 = angle1
        Triangle.angle2 = angle2
        Triangle.angle3 = angle3

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

And the error:

Oops, try again. It looks like your check_angles method doesn't return True for valid triangle angle values.

I have no idea what I am doing wrong. I've even copied the same code from the hint, but nothing have changed.


can we see your full code?


Ok, full code in the top post.


maybe revisit class basics? Your init method is off


What do you mean off?
I revisited, but haven't found any difference.


There is no difference, its the same code. Its about the instructions, to see what you missed.

Well, we have self, we are going to add variables to self (self.angle1) which we are going to give a value (angle1) so we can access our instance variables through self in check_angles method


Hmm... I think I've done this.
And I passed this exercise, when I wrote init___ instead of __init and it worked. It was the only one difference with a code written above, It;s really odd.


no, you created Triangle.angle1 variable in __init__(), not self.angle1

we use self so we can more easily access our instance variables in other methods, this means, in init we need to create them


Yes. I understood. Thank you very much.


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