Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Proofs and refactorizations solution in Clear category for Geometry Figures by veky
import math
class Parameters:
def __init__(self, side): self.side = side
def choose_figure(self, figure): self.unit = figure
def __getattr__(self, attr):
dim = 'perimeter area volume'.split().index(attr) + 1
answer = self.side ** dim * getattr(self.unit, attr)()
return lambda: round(answer, 2)
class UnitShape:
perimeter = lambda self: self.n
area = lambda self: self.n / 4 / math.tan(math.pi / self.n)
volume = lambda self: 0
class Circle(UnitShape):
n = math.tau
area = lambda self: math.pi
class Triangle(UnitShape): n = 3
class Square(UnitShape): n = 4
class Pentagon(UnitShape): n = 5
class Hexagon(UnitShape): n = 6
class Cube(UnitShape):
n = 12
area = lambda self: 6
volume = lambda self: 1
June 22, 2018
Comments: