Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Simple Areas by bukebuer
import math
def simple_areas(*args):
if len(args)==1:
s = math.pi*(args[0]*0.5)**2
elif len(args)==2:
s = args[0]*args[1]
else:
a, b, c = args
l = sum(args)*0.5
s = (l*(l-a)*(l-b)*(l-c))**0.5
return round(s, 2)
assert almost_equal(simple_areas(3), 7.07), "Circle"
assert almost_equal(simple_areas(2, 2), 4), "Square"
assert almost_equal(simple_areas(2, 3), 6), "Rectangle"
assert almost_equal(simple_areas(3, 5, 4), 6), "Triangle"
assert almost_equal(simple_areas(1.5, 2.5, 2), 1.5), "Small triangle"
May 15, 2014
Comments: