Class it up


#1

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
        else:
            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.


#2

can we see your full code?


#3

Ok, full code in the top post.


#4

maybe revisit class basics? Your init method is off


#5

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


#6

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


#7

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.


#8

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


#9

Yes. I understood. Thank you very much.


#10

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