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 frantisek.jahoda
from math import pi, atanh, asin, sqrt
def checkio(height, width):
a = width / 2
c = height / 2
volume = 4/3*pi*c*a*a
if c == a:
area = 4*pi*a*a
elif c < a:
e = sqrt(1 - c*c / (a*a))
area = 2*pi*a*a * (1 + (1 - e*e) * atanh(e) / e)
else:
e = sqrt(1 - a*a / (c*c))
area = 2*pi*a*a * (1 + c * asin(e) / (a*e))
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"
Sept. 21, 2016