Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
With Ngone class solution in Clear category for Geometry Figures by Phil15
from math import pi, tan
class Ngone:
def perimeter(self, c):return self.n * c
def area(self, c):return c**2 * self.n / 4 / tan(pi/self.n)
def volume(self, c):return 0
class Triangle(Ngone): n = 3
class Square(Ngone): n = 4
class Pentagon(Ngone): n = 5
class Hexagon(Ngone): n = 6
class Circle:
def perimeter(self, r):return 2 * pi * r
def area(self, r):return r**2 * pi
def volume(self, r):return 0
class Cube:
def perimeter(self, c):return 12 * c
def area(self, c):return c**2 * 6
def volume(self, c):return c**3
class Parameters:
def __init__(self, param):
self.param = param
def choose_figure(self, obj):
self.instance = obj
def perimeter(self):
return round(self.instance.perimeter(self.param), 2)
def area(self):
return round(self.instance.area(self.param), 2)
def volume(self):
return round(self.instance.volume(self.param), 2)
Aug. 13, 2018
Comments: