Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Humpty Dumpty Form by Rounin
import math
def checkio(height, width):
volume = (height*4.0*math.pi*(width/2.0)**3.0)/(3.0*width)
surface = 0.5*math.pi*width*width
a = min(width, height)
b = max(width, height)
eccentricity = math.sqrt(1-((a*a)/(b*b)))
if height > width:
surface *= (1+(height/(width*eccentricity))*math.asin(eccentricity))
elif height < width:
surface += (math.pi*0.25*height*height*math.log((1+eccentricity)/(1-eccentricity)))/eccentricity
else:
surface *= 2
return list(map(lambda x: round(x*100)/100, [volume, surface]))
#These "asserts" using only for self-checking and not necessary for auto-testing
if __name__ == '__main__':
assert checkio(4, 2) == [8.38, 21.48], "Prolate spheroid"
assert checkio(2, 2) == [4.19, 12.57], "Sphere"
assert checkio(2, 4) == [16.76, 34.69], "Oblate spheroid"
Sept. 29, 2017