首页 > 其他 > 详细

圆周率进度条

时间:2020-04-01 00:32:14      阅读:97      评论:0      收藏:0      [点我收藏+]
import time
from random import random
scale = 10 
print("执行开始".center(scale//2, "-")) 
start=time.perf_counter()
DARTS=1000*1000
hits=0.0
for i in range(1,DARTS):
    x,y=random(),random()
    dist=pow(x**2+y**2,0.5)
    if dist<=1.0:
        hits=hits+1
pi=4*(hits/DARTS)
for i in range(scale+1):     
    a = ‘*‘ * i     
    b = ‘.‘ * (scale - i)     
    c = (i/scale)*100     
    dur = time.perf_counter() - start     
    print("{:^3.0f}%[{}->{}]{:.2f}s".format(c,a,b,dur))     
    time.sleep(0.1)
print("圆周率值是:{}".format(pi))
print("\n"+"执行结束".center(scale//2,‘-‘))

  

import time
from random import random
scale = 10
print("执行开始".center(scale//2, "-"))
start=time.perf_counter()
DARTS=1000*1000
hits=0.0
for i in range(1,DARTS):
x,y=random(),random()
dist=pow(x**2+y**2,0.5)
if dist<=1.0:
hits=hits+1
pi=4*(hits/DARTS)
for i in range(scale+1):
a = ‘*‘ * i
b = ‘.‘ * (scale - i)
c = (i/scale)*100
dur = time.perf_counter() - start
print("{:^3.0f}%[{}->{}]{:.2f}s".format(c,a,b,dur))
time.sleep(0.1)
print("圆周率值是:{}".format(pi))
print("\n"+"执行结束".center(scale//2,‘-‘))

圆周率进度条

原文:https://www.cnblogs.com/chen123123/p/12609503.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!