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 Krzysztof_Dziedzic
from math import sqrt, pi, asin, pow, atanh
def checkio(height, width):
S = 0
V = 0
e = 0
if height == width:
S = (4 * pi) * (width / 2) ** 2
V = 4 / 3 * pi * pow(width / 2, 3)
S = round(S,2)
V = round(V,2)
return [V, S]
elif height > width:
a = width / 2
c = height / 2
e = sqrt(1 - ((pow(a,2) / pow(c,2))))
S = 2 * pi * pow(a,2) * (1 + ((c / (a * e)) * asin(e)))
V = 4/3 * pi * pow(a,2) * c
V = round(V, 2)
S = round(S, 2)
return [V, S]
else:
a = width / 2
c = height / 2
e = sqrt(1 - ((pow(c,2) / pow(a,2))))
S = 2 * pi * pow(a,2) * (1 + ((1 - pow(e,2)) / e) * atanh(e))
V = 4/3 * pi * pow(a,2) * c
V = round(V, 2)
S = round(S, 2)
return [V, S]
#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"
Nov. 7, 2016