码迷,mamicode.com
首页 > 其他好文 > 详细

圆周率进度条

时间:2020-03-23 22:17:56      阅读:85      评论:0      收藏:0      [点我收藏+]

标签: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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!