16. class it up


#1

What am I doing wrong? it says I don't have the number of side variable but I do??

indent preformatted text by 4 spaces

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

#2

number_of_sides should be condensed into the init method as self.number_of_sides.


#3

tried that now it's telling me global name "Triangle" not defined?


#4

The should be no indents with defs. number_of_sides and defs should be on the same level.

if a == b: - mind your syntax! not if a = b:


#5

Had the same problem and fixed it. In the "If" statement, you have to say == 180 for equality, not = 180 for definition.


#6

Is there a reason why we can't use a sum function here?

I tried
----def check_angles(self):
--------if sum(self.angle1, self.angle2, self.angle3) == 180:
------------return True
--------else:
------------return False
but it didn't work.


#7

The built-in function sum() only sums over an iterable data type such as a list or tuple. You can't pass integers or floats to it as arguments. You can read more about sum() here: https://docs.python.org/2/library/functions.html?highlight=sum#sum