title: calculating pi with monte carlo and while loops
body: <p>trying to calculate pi using this while loop but can not figure out how to stop it once it hits 3.14, it just keeps going infinitely </p>
  
  <pre><code>import turtle
  import math
  import random
  
  t = turtle.Turtle()
  wn = turtle.Screen()
  wn.setworldcoordinates(-400,-400,400,400)
  
  t.pu()
  t.speed(0)
  t.goto(0,-400)
  t.pd()
  t.color("blue")
  t.circle(400)
  t.color("orange")
  hits=0.0
  numdarts =0
  eps=0.01
  actPi=3.1415
  estPi=3
  error=abs(actPi-estPi)
  
  
  
  while abs(error) &gt;= eps:
  
      randx=random.uniform(-1,1)
      randy=random.uniform(-1,1)
      if (randx**2+ randy**2)&lt;1:
          hits+=1.0
      numdarts+=1
      estPi=(hits/numdarts)
      error=abs(actPi-estPi)
      t.pu()
      t.goto(400*randx,400*randy)
      t.pd()
      t.dot()
  
  
  print 4*(hits/numdarts)
  wn.exitonclick()
  </code></pre>
  
  <p>i dont know how to get the loop to stop at 3.14</p>