Class It Up failing to parse my code


#1

https://www.codecademy.com/courses/python-intermediate-en-WL8e4/3/2?curriculum_id=4f89dab3d788890003000096

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)
False
>>> works = Triangle(10,70,100)
>>> works.check_angles(10,70,100)
True
>>>

Does this look like a bug in Codeacademy?


#2

I just saw https://discuss.codecademy.com/t/16-class-it-up/54959 and modifying my code makes it run in codeacaademy

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

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


#3

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.


#4

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


#5

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