Approximating Pi with Python
One of the many approximations of Pi is the Gregory-Leibniz series (image source Wikipedia):
Here is an implementation in Python:
# -*- coding: utf-8 -*- """ Created on Sat Mar 25 06:52:11 2017 @author: Uwe Ziegenhagen """ sum = 0 factor = -1 for i in range(1, 640000, 2): sum = sum + factor * 1/i factor *= -1 # print(sum) print(-4*sum) |