import math """Estimates the value of pi Uses the secant of successivly smaller slices of a unit circle as an estimate of the circumference """ # Initial value is the hypotenuse of a quarter of a circle # 2pi ~ 4 * srt(2) # pi ~ 2 * sqrt(2) # x is the length of the secant x = math.sqrt(2) N = 2 print('The estimate of pi is') for i in range(30): y = math.sqrt(1 - (x / 2)**2) z = 1 - y x = math.sqrt((x / 2)**2 + z**2) N *= 2 pi = N * x print('{0:d}, {1:.20f}'.format(i, pi))