16. Class it up, I'd appreciate the help!


#1

My code:

Class Triangle(object):
number_of_sides = 3
def check_angles(self):
if self.angle1 + self.angle2 + self.angle3 == 180:
return True
else:
return False

def __init__(self, angle1, angle2, angle3):
    self.angle1 = angle1
    self.angle2 = angle2
    self.angle3 = angle3

The error message: "Oops, try again. It looks like your Triangle class doesn't have a number_of_sides member variable."
I've seen various other similar posts but I still fail to see why my code is incorrect as the variable number_of_sides surely is there. I'm slowly tearing my hair out, over this seemingly easy error.
Any idea of what I'm doing wrong?


#2

I failed to show the correct indentations in the post above where (1) indentation=4 spaces
(0) Class Triangle(object):
(1) number_of_sides = 3
(1) def check_angles(self):
(2) if self.angle1 + self.angle2 + self.angle3 == 180:
(3) return True
(2)else:
(3) return False
(1)def init(self, angle1, angle2, angle3):
(2) self.angle1 = angle1
(2) self.angle2 = angle2
(2) self.angle3 = angle3


#3

Can anyone shed light on this please

class Triangle(object):
def init(self, angle1, angle2, angle3):
self_angle1 = angle1
self_angle2 = angle2
self_angel3 = angle3

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

it is giving me a Oops, try again. Your code caused the following error: 'Triangle' object has no attribute 'angle1' error.


#4

Hi first here

self_angle1 = angle1
self_angle2 = angle2
self_angel3 = angle3

your self_angle should be with a . dot instead of the _

then the self.angle3 you wrote self.angel3


#5

Hi this part

Class Triangle(object):

you should remove the uppercase C on class


#6

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


#7

is there problem?
i have confused guys i need a help please


#8

Hi your code is fine it's maybe a indent problem so here your code with the rigth indent

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

#9

thanks a lot for the code i have just finished alluliiai


#10

hello
why "def check_angles(self): "instead of "def check_angles(self,angle1,angle2,angle3):"
can u explain that,, thax


#11

I get the same problem and have added debug code making a triangle and printing the variable.
The interpreter loves it, but codeacademy does not. The indentation on my code is good, and I have refreshed the page. In fact, I tried it once as systemmaster51140 has it, and once where I initialized the variable inside init.
The interpreter likes it both ways.


#12

number_of_sides=3 must be directly under the class definition.


#13

I got out of codeacademy. Logged back in. Positioned number_of_side=3 as you said. Now CA likes it and I can continue. Thanks, my problem is resolved.


#14

its a bug at the init() part. idk why but it worked after i deleted the __ and remained init() instead of __ init __()


#15

Thanks! There's definitely a bug here where you have to remove the four underscores for init!


#16

there is no space between angle and 1


#17