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 Oleg_Domokeev
from math import sqrt, pi, asin, atanh
def checkio(height, width):
if height > width:
e = sqrt(height ** 2 - width ** 2) / height
return [round(pi * height * width ** 2 / 6, 2), round(0.5 * pi * width ** 2 * (1 + height * asin(e) / width / e), 2)]
elif height == width:
return [round(pi * height ** 3 / 6, 2), round(pi * height ** 2, 2)]
else:
e = sqrt(width ** 2 - height ** 2) / width
return [round(pi * height * width ** 2 / 6, 2), round(0.5 * pi * width ** 2 * (1 + (1 - e ** 2) * atanh(e) / e), 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"
July 27, 2018
Comments: