Why this code works but the other doesn't?


#1



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


Question is why this code works just fine :


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

but this one doesn't:

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

Sum should do the addition of all arguments in parentheses, shouldn't it ?


#2

Is sum designed to behave that way? If not, then you can't.
Look up what things do. They have a certain behaviour no matter what you do with them. Using a hammer to turn a screw won't be very effective, using a hammer that way won't make it a screwdriver, it is the way it is and it's up to you to make use of the behaviour that it does exhibit.


#3

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