Why does the Triangle class not inherit the number_of_sides function from the Shape class? Or what syntax would I use to call inherit the number_of_sides attribute from Shape? The code below results in an error because Triangle doesn't have number of sides defined.
class Shape(object): """Makes shapes!""" def __init__(self, number_of_sides): self.number_of_sides = number_of_sides class Triangle(Shape): '''Makes triangles''' def __init__(self,side1,side2,side3): self.side1=side1 self.side2=side2 self.side3=side3 a=Shape(4) print a.number_of_sides a=Triangle(3,4,5) print a.side1 print a.number_of_sides
Results in an error
4 3 Traceback (most recent call last): File "python", line 19, in <module> AttributeError: 'Triangle' object has no attribute 'number_of_sides'`