16. Class it up?


#1

Hi!
One simple question, regarding the code below, is there a simple and quicker way of adding all the angles together? I tried using the sum() function, but that didn’t work.

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


#2

You’ll have to list all three of them regardless, so there’s not much to save, is there?
Something which is redundant though, is to return true when the result true and return false when the result is false - return the result instead, since it is the same.


#3

Who are we writing this for? If it’s one’s self, then use the terms that are most meaningful to you. Is there some math training in your background? Then a, b, c are pretty much the norm. Use those terms since they are so familiar and their meaning will not be displaced by the language.

As @ionatan pointed out, a simple return statement is moot.

return self.a + self.b + self.c == 180

#4

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