title: Leibniz formula for π - Is this any good? (Python)
body: <p>I'm doing an exercise that asks for a function that approximates the value of pi using Leibniz' formula. These are the explanations on Wikipedia:</p>
  
  <p><img src="https://i.stack.imgur.com/BmZlF.png" alt="enter image description here"></p>
  
  <p><img src="https://i.stack.imgur.com/Tihza.png" alt="enter image description here"></p>
  
  <p>Logical thinking comes to me easily, but I wasn't given much of a formal education in maths, so I'm a bit lost as to what the leftmost symbols in the second one represent. I tried to make the code <code>pi = ( (-1)**n / (2*n + 1) ) * 4</code>, but that returned <code>1.9999990000005e-06</code> instead of 3.14159..., so I used an accumulator pattern instead (since the chapter of the guide that this was in mentions them as well) and it worked fine. However, I can't help thinking that it's somewhat contrived and there's probably a better way to do it, given Python's focus on simplicity and making programmes as short as possible. This is the full code: <br></p>
  
  <pre><code>def myPi(n):
      denominator = 1
      addto = 1
  
      for i in range(n):
          denominator = denominator + 2
          addto = addto - (1/denominator)
          denominator = denominator + 2
          addto = addto + (1/denominator)
  
      pi = addto * 4
  
      return(pi)
  
  print(myPi(1000000))
  </code></pre>
  
  <p>Does anyone know a better function?</p>