import math class Shape(object): def __init__(self, x, y, z): self.center = (x, y, z) class Shape2D(Shape): def __init__(self, x, y): Shape.__init__(self, x, y, 0) def perimeter(self): raise NotImplementedError def area(self): raise NotImplementedError class Shape3D(Shape): def surface_area(self): raise NotImplementedError def volume(self): raise NotImplementedError class Rectangle(Shape2D): def __init__(self, x, y, height, width): Shape2D.__init__(self, x, y) self.height = height self.width = width def perimeter(self): return 2*self.width + 2*self.height def area(self): return self.width*self.height class Square(Rectangle): def __init__(self, x, y, length): Rectangle.__init__(self, x, y, length, length) class Circle(Shape2D): def __init__(self, x, y, radius): Shape2D.__init__(self, x, y) self.radius = radius def perimeter(self): return 2*math.pi*self.radius def area(self): return math.pi*(self.radius)**2 class RectangularPrism(Shape3D): def __init__(self, x, y, z, length_x, width_y, height_z): Shape3D.__init__(self, x, y, z) self.length = length_x self.width = width_y self.height = height_z def surface_area(self): return 2*self.length*self.width + 2*self.length*self.height + 2*self.width*self.height def volume(self): return self.length*self.width*self.height class Cube(RectangularPrism): def __init__(self, x, y, z, length): RectangularPrism.__init__(self, x, y, z, length, length, length) class Sphere(Shape3D): def __init__(self, x, y, z, radius): Shape3D.__init__(self, x, y, z) self.radius = radius def surface_area(self): return (4.0/3.0)*math.pi*self.radius**2 def volume(self): return 4*math.pi*self.radius**3