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 tssrkt777
from math import pi, asin, atanh
def checkio(h, w):
a, b = h / 2, w / 2
if h > w: # prolate
e = (1 - (b ** 2 / a ** 2)) ** 0.5
s = 2 * pi * b ** 2 * (1 + (a / (b * e)) * asin(e))
elif h < w: # oblate
e = (1 - (a ** 2 / b ** 2)) ** 0.5
s = 2 * pi * b ** 2 * (1 + ((1 - e ** 2) / e) * atanh(e))
else: # sphere
s = 4 * pi * a ** 2
return [round((pi / 6) * w ** 2 * h, 2), round(s, 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"
Oct. 6, 2021
Comments: