Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
(context) manager of decorations solution in Clear category for Simple Areas by veky
import math, contextlib
areas = []
def half(x): return x / 2
@areas.append
def circle(diameter): return half(diameter)**2 * math.pi
@areas.append
def rectangle(width, height): return width * height
@areas.append
def triangle(a, b, c):
"""Heron's formula"""
s = half(a + b + c)
return math.sqrt(s*(s-a)*(s-b)*(s-c))
def simple_areas(*args):
for area in areas:
with contextlib.suppress(TypeError): return area(*args)
Nov. 10, 2020
Comments: