Class It Up failing to parse my code


I'm seeing an unexpected error when running my code in the "Class it up" task.

 Oops, try again. Make sure to pass self as an argument to your check_angles method!

I'm baffled because the code appears to work correctly in an actual python interpretor.

$ python
Python 2.7.10 (default, Jun  1 2015, 18:05:38)
[GCC 4.9.2] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 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):
...         if (angle1 + angle2 + angle3) == 180:
...             return True
...         else:
...             return False
>>> my = Triangle(10,90,40)
>>> my.check_angles(10,90,40)
>>> works = Triangle(10,70,100)
>>> works.check_angles(10,70,100)

Does this look like a bug in Codeacademy?


I just saw and modifying my code makes it run in codeacaademy

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

I'm still interested to know if/why the former doesn't work.


You would tell a function the angles to check, but a method of an object does not need to be told information it already has access to.

It still ran.


Thanks for the quick reply! I'll try doing some experiments to help clear it up in my mind.


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