Home > Python >Python Exercise: Find PI

Find PI

We can calculate the value of Pi by calculating the half perimeter of the regular n-polygon inscribed in a unit circle. When the n is large enough, the calculated value will be close to Pi. To calculate the side length of a n-polygon inscribed in a unit circle, you can use the following formula: \[ a_{2n}=\sqrt{2 - \sqrt{4-a_n^2}} \] The formula find the side length of a regular 2n-polygon based on the side length of a regular n-polygon. You can start with n = 6, \(a_6 = 1\).

You need login to comment

Solution submitted by Dzeng at April 29, 2020, 6:02 p.m.
def findpi(n, a, iterations): for i in range (0, iterations): a = (2 - ((4 - a**2)**(1/2)))**(1/2) n = n * 2 print(a * n / 2) findpi(6, 1, 15)

You need login to submit your solution