title: Need help calculating pi in python with while function
body: <p>Hey I'm new to Python and decided to try to make a program that calculates pi to as many decimal places as possible. </p>
  
  <p>I used radii of the circle to form two sides of a triangle, with angle x between them, and used cosine law to find the length of the opposite side. Then I multiply by 360/x to get the perimeter of a polygon with # of sides approaching infinity to make a circle. </p>
  
  <p>I've tried it in a calculator and it works but in python then number is  way off and I can't seem to fix it. </p>
  
  <p>Can someone help me out here?</p>
  
  <pre><code>import math
  
  n = 1
  
  while True:
    def angle(x):
      y = 360 / x
      z = y * (  (0.5 - (math.cos(math.degrees(x))  *0.5)  )**0.5)
  
      print(z)
  
      return x
  
    n = (n + 1)
    angle(45 / n)
  </code></pre>