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 cs1g
from math import asin, atanh, pi, sqrt
def checkio(height, width):
if height == width:
S = pi * width ** 2
elif height < width:
ee = 1 - (height / width) ** 2
e = sqrt(ee)
S = pi * width ** 2 * (1 + (1 - ee) * atanh(e) / e) / 2
else:
ee = 1 - (width / height) ** 2
e = sqrt(ee)
S = pi * width ** 2 * (1 + height * asin(e) / (width * e)) / 2
V = pi * height * width ** 2 / 6
return [round(V, 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"
July 13, 2017
Comments: