I'm experimenting with the code in this section to better understand the concept of inheritance.
I just created a new method called display_sides() in Class Shape. However when i ran the code it doesn't totally work. here is the output, in bold:
Traceback (most recent call last):
** File "python", line 24, in **
** File "python", line 7, in display_sides**
AttributeError: 'Triangle' object has no attribute 'number_of_sides'
I had expected the final line of the output to be 3. but instead, this just threw an error ... which doesn't make sense (it's not clear to me why Triangle didn't inherit number_of_sides from Shape)
below is the code. any suggestions? what am i missing?
class Shape(object): """Makes shapes!""" def __init__(self, number_of_sides): self.number_of_sides = number_of_sides def display_sides(self): print 'test_print' print self.number_of_sides class Triangle(Shape): def __init__(self, side1, side2, side3): self.side1 = side1 self.side2 = side2 self.side3 = side3 my_shape = Shape(3) my_triangle = Triangle('a', 'b', 'c') print my_shape.display_sides() print my_triangle.side1 print my_triangle.side2 print my_triangle.side3 print print my_triangle.display_sides()