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 maciejmoscicki
import math
def checkio(height, width):
wysokosc = float(height)
szerokosc = float(width)
lista = []
if wysokosc == szerokosc:
r = 0.5 * szerokosc
pole = 4 * math.pi * r**2
pole = round(pole, 2)
objetosc=4 * math.pi* (r**3) /3
objetosc = round(objetosc,2)
lista.append(objetosc)
lista.append(pole)
elif wysokosc > szerokosc: #If spheroid is prolate
a = 0.5 * szerokosc
b = 0.5 * wysokosc
e2 = 1 - a**2 / b**2
e = (e2**(1/2))
pole = 2 * math.pi * a**2 * (1 + b / (a * e) * math.asin(e))
pole = round(pole, 2)
objetosc = 4 * math.pi / 3 * a * a * b
lista.append(objetosc)
lista.append(pole)
elif wysokosc < szerokosc: #If spheroid is oblate
a = 0.5 * szerokosc
b = 0.5 * wysokosc
e2 = 1 - b**2 / a**2
e = (e2**(1/2))
pole = 2 * math.pi * a**2 * (1 + (1 - e2) / e * math.atanh(e))
pole = round(pole, 2)
objetosc = 4 * math.pi / 3 * a * a * b
lista.append(objetosc)
lista.append(pole)
return lista
#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"
Oct. 9, 2016