Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Humpty Dumpty Form by robert.rudko
import math
def checkio(h, w):
a = w / 2.0
b = h / 2.0
V = ((4*math.pi)/3)*((a**2)*(b))
V = round(V,2)
if h == w:
S = 4 * math.pi * a**2
S = round(S, 2)
elif h > w:
e = math.sqrt(1 - a**2 / b**2)
S = 2 * math.pi * a**2 * (1 + ((b / (a * e)) * math.asin(e)))
S = round(S, 2)
elif h < w:
e2 = 1 - b**2 / a**2
e = math.sqrt(e2)
S = 2 * math.pi * a**2 * (1 + ((1 - e2) / e) * math.atanh(e))
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. 23, 2015