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 brownie57
import math
def checkio(height, width):
pi = math.pi
h = height/2
w = width/2
v = 4/3*pi*h*w**2
e = math.sqrt(1-(min(h, w)/max(h, w))**2)
if h > w:
s = 2*pi*(w**2+h*w*math.asin(e)/e)
elif h < w:
s = 2*pi*(w**2+h**2*math.atanh(e)/e)
else:
s = 4*pi*h*w
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 19, 2018
Comments: