Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Simple Areas by Luker
import math
def simple_areas(*args):
input=args
if len(input)==1:
return (round((input[0]/2)**2*math.pi,2))
if len(input)==2:
return (input[0]*input[1])
if len(input)==3:
s=(input[0]+input[1]+input[2])/2
return (round((s*(s-input[0])*(s-input[1])*(s-input[2]))**0.5,2))
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
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"
Nov. 21, 2016