#! /usr/bin/python3
import math
import sys
a = float(sys.argv[1])
b = float(sys.argv[2])
h = ((a - b) / (a + b))**2
eps = sys.float_info.epsilon
def binom_half(n):
coef = 1.0
for k in range(n):
coef *= (0.5 - k) / (k + 1)
return coef
perimeter = 0.0
n = 0
term = 1.0
while abs(term) > eps:
coef = binom_half(n)
term = (coef**2) * h**(2*n)
perimeter += term
n += 1
perimeter *= math.pi * (a + b)
print(f"Ellipse perimeter: {perimeter:.17f}")
print(f"Series converged after {n} terms")

About Linuxgal
Need a spiritual home? Consider joining us at Mary Queen of the Universe Latter-day Buddhislamic Free Will Christian UFO Synagogue of Vishnu