Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Humpty Dumpty Form solution in Clear category for Humpty Dumpty Form by Druggist
from math import *
def checkio(height, width):
a = width/2
c = height/2
if height == width:
return(round(4/3 * pi * c**3 ,2), round(4 * pi * c**2,2))
area = 0
volume = ((4*pi) / 3) * a * a * c
if height < width:
e = sqrt(1 - (c**2 / a**2))
area = 2 * pi * a*a * (1 + ((1 - e**2) / e) * atanh(e))
else:
e = sqrt(1 - (a**2 / c**2))
area = 2 * pi * a*a * (1 + (c / (a*e)) * asin(e))
return [round(volume,2), round(area,2)]
print(checkio(2, 4))
#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"
Dec. 5, 2016