Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Geometry Figures by mozurin
import math
class Parameters:
def __init__(self, param):
self.param = param
def choose_figure(self, figure):
self.figure = figure
def __getattr__(self, func_name):
def delegate():
return round(getattr(self.figure, func_name)(self.param), 2)
return delegate
class Circle:
def perimeter(self, r):
return 2 * math.pi * r
def area(self, r):
return math.pi * r**2
def volume(self, r):
return 0
class Polygone:
VERTS = 0
def perimeter(self, edge):
return edge * self.VERTS
def area(self, edge):
return self.VERTS * edge**2 / (4 * math.tan(math.pi / self.VERTS))
def volume(self, edge):
return 0
class Triangle(Polygone):
VERTS = 3
class Square(Polygone):
VERTS = 4
class Pentagon(Polygone):
VERTS = 5
class Hexagon(Polygone):
VERTS = 6
class Cube:
def perimeter(self, edge):
return edge * 12
def area(self, edge):
return edge**2 * 6
def volume(self, edge):
return edge**3
June 30, 2018