Class it up ! doubt!


#1

i have a doubt in check_angles code block : if i set angles then the codecademy says error but if remove

self.angle1=angle1

    self.angle2=angle2
    self.angle3=angle3   from my  check_angles method it works fine : please explain it to me!

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):
        self.angle1=angle1
        self.angle2=angle2
        self.angle3=angle3
        if self.angle1+self.angle2+self.angle3==180:
            return True
        else:
            False

#2

Hi @sranjan,

I'm not yet getting what you mean could you please explain further?


#3

well, init boots up the class. Here we make our instance variables (self.angle1, self.angle2 and self.angle3), which we can then use in other methods

otherwise, we would have to supply the 3 angles everytime we want to call a method, which wouldn't be very DRY


#4

why he has to remove:

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

from check_angles method to make it work


#5

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