Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Creative category for Simple Areas by panaro32
from math import pi
def simple_areas(a,b=0,c=0):
return (pi*a*a/4,a*b,((a+b+c)*(b+c-a)*(a+c-b)*(a+b-c))**.5/4)[2-(a,b,c).count(0)]
if __name__ == '__main__':
def almost_equal(checked, correct, significant_digits=2):
precision = 0.1 ** significant_digits
return correct - precision < checked < correct + precision
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"
June 14, 2014