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 Lipen
from math import *
def checkio(height, width):
a,b = width/2., height/2.
V = 4/3*pi*a**2*b
if a==b:
S = 4*pi*a**2
elif a>b:
S = 2*pi*a*(a + b**2/sqrt(a**2-b**2)*log((a+sqrt(a**2-b**2))/b))
else:
S = 2*pi*a*(a + b**2/sqrt(b**2-a**2)*asin(sqrt(b**2-a**2)/b))
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"
Sept. 20, 2014