Class it up


#1



I got the code to work ok, but I'm wondering why I don't need to add the angle1-3 arguements to the check_angles function? In previous section we did add the "hours" arguement and not only "self".


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.angle1 + self.angle2 + self.angle3 == 180:
            return True
        else:
            return False


#2

A triangle object knows its angles (wouldn't be much of a triangle otherwise)

Telling the triangle which angles it has when asking if its angles are valid.. doesn't make a whole lot of sense

Sidenote: If the angles are floats then testing whether the sum is equal to 180 is a bug. It should instead test if it's very close to 180 as floats are not able to represent all values exactly and are as such approximations.

>>> import math
>>> math.isclose(180.0, 180)
True

#3

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