Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Geometry Figures by David_Jones
from math import pi
SIZE = 0
class Parameters:
def __init__(self, size):
globals()['SIZE'] = size
def choose_figure(self, object):
self.object = object
def perimeter(self):
return self.object.perimeter()
def area(self):
return self.object.area()
def volume(self):
return self.object.volume()
approximate = lambda x: round(x, 2) if x % 1 else int(x)
class Circle:
def __init__(self):
self.radius = globals()['SIZE']
def perimeter(self):
return approximate(2 * pi * self.radius)
def area(self):
return approximate(pi * self.radius**2)
def volume(self):
return 0
class Triangle:
def __init__(self):
self.side = globals()['SIZE']
def perimeter(self):
return approximate(3 * self.side)
def area(self):
return approximate(3**.5 / 4 * self.side**2)
def volume(self):
return 0
class Square:
def __init__(self):
self.side = globals()['SIZE']
def perimeter(self):
return approximate(4 * self.side)
def area(self):
return approximate(self.side**2)
def volume(self):
return 0
class Pentagon:
def __init__(self):
self.side = globals()['SIZE']
def perimeter(self):
return approximate(5 * self.side)
def area(self):
return approximate(5 * self.side**2 / (4 * (5-2*5**.5)**.5))
def volume(self):
return 0
class Hexagon:
def __init__(self):
self.side = globals()['SIZE']
def perimeter(self):
return approximate(6 * self.side)
def area(self):
return approximate(3 / 2 * 3**.5 * self.side**2)
def volume(self):
return 0
class Cube:
def __init__(self):
self.side = globals()['SIZE']
def perimeter(self):
return approximate(12 * self.side)
def area(self):
return approximate(6 * self.side**2)
def volume(self):
return self.side**3
May 21, 2019