标签:orm range imp rand hits int 进度条 end math
from random import random
import math
import time
DARTS=1000000
hits=0.0
for i in range(1,DARTS):
x,y=random(),random()
dist=math.sqrt(x**2+y**2)
if dist<=1.0:
hits=hits+1
pi=4*(hits/DARTS)
for i in range(10):
a=‘>‘*i
b=‘-‘*(10-i)
print("\r[{}{}]".format(a,b),end="")
time.sleep(0.1)
print("圆周率PI的值是{}.".format(pi))
标签:orm range imp rand hits int 进度条 end math
原文地址:https://www.cnblogs.com/Lysim/p/12555302.html