Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Simple Areas by Daniel_Pereira
from math import pi as PI
def circle(diameter):
return PI * diameter**2 / 4
def rectangle(width, height):
return width * height
def triangle(a, b, c):
p = (a + b + c) / 2
return (p * (p - a) * (p - b) * (p - c)) ** 0.5
_N_ARGS_FUNCTION_MAPPING = {
1: circle,
2: rectangle,
3: triangle
}
def simple_areas(*args):
return round(_N_ARGS_FUNCTION_MAPPING[len(args)](*args), 2)
Feb. 8, 2016