Instantiate an object - TypeError: check_angles() takes exactly 4 arguments (1 given)


#1



https://www.codecademy.com/en/courses/python-intermediate-en-WL8e4/3/3

Traceback (most recent call last):
File "python", line 12, in
TypeError: check_angles() takes exactly 4 arguments (1 given)

Should have given out put of True


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, angle1, angle2, angle3):
        return (angle1 + angle2 + angle3) == 180

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


#2

Please read the error carefully:

check_angles() takes exactly 4 arguments (1 given)

And see what you are doing:

print my_triangle.check_angles()

Can you spot the problem? :wink:


#3

I see that you are setting up args for check_angles method. You don't have to. The self.angle variables are member variables and can be used anywhere within the class.

Try just
def check_angles():
combine = self.angle1 + self.angle2 + self.angle3 #Can't use sum() because it only takes 2 args
if combine == 180:
return True
else:
return False