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 Tinus_Trotyl
from math import pi, sqrt, asin, log
def checkio(height, width):
a, b = width/2, height/2 # radii
V = 4*pi * a*a*b / 3 # Volume
Afs = 2*pi * a*a # Area of a flat sphere (is 2 times a circle)
if b == a : # if a spfere
A = Afs + 2 * pi*b*b # 'blow it up'
elif b > a : # else if prolate
A = Afs + 2 * pi*b*b * (a/sqrt(b*b - a*a) * asin(sqrt(b*b - a*a) / b))
else: # else oblate
el = sqrt(1 - ((b*b) / (a*a)))
A = Afs + 2 * pi*b*b * (log((1+el) / (1-el)) / (2 * el))
return [round(V, 2), round(A, 2)]
Aug. 3, 2017
Comments: