import turtle as t
for i in range(4):
t.pensize(2)
t.fd(200)
t.left(90)
t.penup()
t.goto(200,0)
t.pendown()
t.seth(90)
t.circle(200,90)
from random import random
import math
t.tracer(False)
DARTS=10000
hits=0.0
for i in range(1,DARTS+1):
x,y=random(),random()
dist=math.sqrt(x**2+y**2)
t.penup()
t.goto(x*200,y*200)
t.pendown()
if dist<=1.0:
hits=hits+1
t.dot(3,"red")
else:
t.dot(3,"blue")
pi=4*(hits/DARTS)
t.penup()
t.goto(210,210)
t.pendown()
t.write("pi的值为{}".format(pi))
t.tracer(True)
t.done()
10-21
6855
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)