17, I receive message that my triangle takes no parameters


#1

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

my_triangle = Triangle(90,30,60)
print my_triangle.number_of_sides
print my_triangle.check_angles()


#2

Perhaps you misnamed the __init__ method, the __init__ inherited from object doesn't take any arguments.

BTW, take care to get the formatting right when you post code, if you copy the code in your post into the editor and run it, you'll notice that you'll get different errors.


#3
class Triangle(object):
    number_of_sides = 3
    def __init__(self, angle1, angle2, angle3):
        self.angle1 = angle1
        self.angle2 = angle2
        self.angle3 = angle3
    def check_angles(self):
        if (self.angle1 + self.angle2 + self.angle3) == 180:
            return True
        else:
            return False
            
my_triangle = Triangle(90, 30, 60)
print my_triangle.number_of_sides
print my_triangle.check_angles()

can't tell without formatting but my guess is that you had indented the bottom three lines when you should not have


#5

That is more simple:
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.number_of_sides == 3:
return True
elif self.number_of_sides == 180:
return False
else:
return 0
my_triangle = Triangle(90, 30, 60)
print my_triangle.number_of_sides
print my_triangle.check_angles()


#6

I don't know why but the instructions are wrong. It wants you to put in:

print my_triangle.check_angles()

Do that, WRONG.
Erase that, and

print my_triangle.number_of_sides

should be the last line.
If you do that, it gives you a green.


#7

@ beybladerextreme

I thought so initially as well but then there is something wrong with your code I had:

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

but it should of been slightly different all though the above gave me a pass. I changed the sum part and also the arguments this caused my code to get an error if I don't say

print my_triangle.check_angles()

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

so the whole block of code that prints correct values and gets a pass is like suggested is:

class Triangle(object):
    number_of_sides = 3
    def __init__(self,angle1,angle2,angle3):
        self.angle1 = angle1
        self.angle2 = angle2
        self.angle3 = angle3
    def check_angles(self):
        if self.angle1 + self.angle2 + self.angle3 ==180:
            return True
        else:
            return False
            
my_triangle = Triangle(90,30,60)
print my_triangle.number_of_sides
print my_triangle.check_angles()

#8

thanks @scriptmaster ...it helps me to clear this out..:grin:


#9

Same code returns 3 & True but still gives "Oops, try again. Did you create an instance of Triangle called my_triangle?" error.... This is frustrating!


#10


#11

have even tried changing the sequence of angles in the print.....check_angle(a1,a2,a3)statement


#12

got it ....indentation of the print statements!


#13

I have copied and pasted the exact same code and it is still giving me an error.


#14

@tyriverag: Like it was commented in earlier posts, make sure you instanciate the object outside it's class scope, otherwise the compiler will go crazy about it.
In other words, pay attention to indentation.

If it still doesn't work, post the code so we can take a look!


#15

The init function seems to be named wrong (it's supposed to be __init__)
Here's my code that works:

class Triangle(object):
    number_of_sides = 3
    def __init__(self, angle1, angle2, angle3):
        self.angle1 = angle1
        self.angle2 = angle2
        self.angle3 = angle3
    def check_angle(self):
        if self.angle1 + self.angle2 + self.angle3 == 180:
            return True
        else:
            return False

my_triangle = Triangle(90, 60, 30)
print my_triangle.number_of_sides
print my_triangle.check_angle()

just check the init function, as that uses parameters
By the way, this comment is meant the very top post


#16

I had number_of_sides == 3 and it took forever to pass this exercise


#17

Why doesn't this work? The editor is ■■■■■■■ ■■■■■■■■ My indentation is fine I just cant post it

class Triangle(object):
number_of_sides = 3
def init(self, angle1, angle2, angle3):
self.angle1 = angle1
self.angle2 = angle2
self.angle3 = angle3
def check_angles(self):
if self.angle1+self.angle2+self.angle3 == 180:
return True
else:
return False
my_triangle = Triangle(90,60,30)
print my_triangle.number_of_sides
print my_triangle.check_angles()