from __future__ import print_function from rectangle import Rectangle class Square(Rectangle): """Represents a square in 2-D space.""" def __init__(self, x, y, side): # Create a rectangle whose width and height are # the same as the length of side of the square Rectangle.__init__(self, x, y, side, side) if __name__ == "__main__": print("create square") s = Square(10, 20, 12) # Note that we are using the inherited __repr__ # and area methods. We should probably override # the __repr__ method since squares only have one # dimension parameter (side instead of widthxheight). print("s:", s, "area:", s.area()) class Circle(Square): """Represents a circle in 2-D space.""" def area(self): from math import pi radius = self.width / 2.0 return pi * radius * radius if __name__ == "__main__": print("create circle") c = Circle(10, 20, 12) # Note that we are using the inherited __repr__ # and area methods. We should probably override # the __repr__ method since squares only have one # dimension parameter (side instead of widthxheight). print("c:", c, "area:", c.area())