Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Compute volume and area of a spheroid solution in Clear category for Humpty Dumpty Form by Phil15
from math import pi, sqrt, log, asin
def checkio(height, width):
"""
Compute volume and area of a spheroid.
"""
h = height/2
w = width/2
volume = (4*pi/3)*h*w**2
if hw:
ecc = sqrt(1 - (w/h)**2)
area = 2*pi*w**2*(1+h/w/ecc*asin(ecc))
else: #Sphere h=w
area = 4*pi*h*w
return [round(volume, 2), round(area, 2)]
#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"
March 2, 2018