Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Humpty Dumpty Form by Krzysztof_bonczyk
from math import pi,asin,atanh
def checkio(height, width):
h=height/2
r=width/2
v=4*pi*r*r*h/3
v=round(v,2)
if(h>r):
e=(1-(r*r)/(h*h))**0.5
s=2*pi*r*r*(1+(h/(r*e))*asin(e))
elif (r>h):
e=(1-(h*h)/(r*r))**0.5
s=2*pi*r*r*(1+((1-e*e)/e*atanh(e)))
else:
s=4*pi*r*r
s=round(s,2)
return [v, s]
#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"
Nov. 30, 2016