操作说明
点击即可
VIP:importturtle,randomasrturtle.tracer(0)R=250t=turtle.Turtle()t.speed(0)t.pu()t.goto(-R,R)t.pd()for i in range(4):t.fd(2*R)t.rt(90)t.fd(R)t.seth(180)t.circle(R)m,n=0,0t.pu()pen=turtle.Turtle()pen.pu()pen.goto(-250,-300)FONT=("system",30,'normal') while 1:m+=1x,y=r.randint(-R,R),r.randint(-R,R)t.goto(x,y)if t.distance(0,0)<=R:n+=1t.dot(5,"red")else:t.dot(5,"black")pi=round(n/m*4,6)w='π≈'+str(pi)+'['+str(n)+':'+str(m)+']'pen.clear()pen.write(w,font=FONT)turtle.update()