• Humpty Dumpty Form problem

 

Mission: https://py.checkio.org/ru/mission/humpty-dumpty/

I added formula from: https://en.wikipedia.org/wiki/Spheroid

It counts not correct surface and in oblate shows this error:

ZeroDivisionError: float division by zero

How to resolve it?

Thank you a lot.

from math import pi, asin, atan


def checkio(h, w):
    if h > w:  # prolate
        e = (1 - (w ** 2 / h ** 2)) ** 0.5
        s = 2 * pi * w ** 2 * (1 + (h / (w * e))) * asin(e)
    else:  # oblate
        e = (1 - (h ** 2 / w ** 2)) ** 0.5
        s = 2 * pi * w ** 2 * (1 + ((1 - e ** 2) / e) * atan(e))
    return [round(pi / 6 * 2 * w * h, 2), round(s, 2)]


print(checkio(4, 2))  # == [8.38, 21.48]
print(checkio(2, 2))  # == [4.19, 12.57]
print(checkio(2, 4))  # == [16.76, 34.69]