Shapes ====== Exercise -------- * Complete the ```Ellipse(Shape)``` class definition * Complete the ```scale(self, factor)``` method within the class definition ```Shape()``` * Add a method to the each of the classes ```Rectangle(Shape)```, ```Triangle(Shape)```, and ```Ellipse(Shape)``` to calculate the perimeters of the different shapes .. interactive_code_block:: :caption: Complete the Ellipse(Shape) class definition, the scale() method, and add a method to calculate the perimeters of the three different shapes class Shape(): def __init__(self, w, h): # Special method name __init__: this method gets called when an instance of the class is created self.width = w # Instance variable self.height = h def scale(self, factor): # Method definition pass # ... class Rectangle(Shape): # The class 'Rectangle will 'inherit' everything from the class 'Shape' def area(self): return self.width * self.height class Triangle(Shape): # Isosceles triangle = two sides of equal length [^1] def area(self): return self.width * self.height / 2 class Ellipse(Shape): def area(self): pass # ... # Creating instances of the classes r1 = Rectangle(10, 20) r2 = Rectangle(20, 30) t = Triangle(20, 30) e = Ellipse(40, 50) print('\\n Shape | Width | Height | Area ') print('------------+--------+--------+---------------') print('Rectangle 1 | {:6.2f} | {:6.2f} | {:13.3f}'.format(r1.width, r1.height, r1.area())) print('Rectangle 2 | {:6.2f} | {:6.2f} | {:13.3f}'.format(r2.width, r2.height, r2.area())) print('Triangle | {:6.2f} | {:6.2f} | {:13.3f}'.format(t.width, t.height, t.area())) print('Ellipse | {:6.2f} | {:6.2f} | {:13.3f}'.format(e.width, e.height, e.area())) r1.scale(1.5) # Call the scale method print('Rectangle 1 | {:6.2f} | {:6.2f} | {:13.3f}'.format(r1.width, r1.height, r1.area())) # Output: # # Shape | Width | Height | Area # ------------+--------+--------+--------------- # Rectangle 1 | 10.00 | 20.00 | 200.000 # Rectangle 2 | 20.00 | 30.00 | 600.000 # Triangle | 20.00 | 30.00 | 300.000 # Ellipse | 40.00 | 50.00 | 1570.796 # Rectangle 1 | 15.00 | 30.00 | 450.000 """ [^1]: https://en.wikipedia.org/wiki/Isosceles_triangle """