zoukankan      html  css  js  c++  java
  • 用python计算圆周率并用进度条并显示计算进度

     1 import math
     2 import time
     3 scale=20
     4 s,m,=1,2
     5 total,s,n,t=0.0,1,1.0,1.0
     6 print("执行开始".center(scale//2, "-"))
     7 start = time.perf_counter()
     8 for i in range(scale+1):
     9     total+=t
    10     n+=2
    11     s=-s
    12     t=s/n
    13     k=total*4
    14     a = '*' * i 
    15     b = '.' * (scale - i)
    16     c = (i/scale)*100 
    17     dur = time.perf_counter() - start 
    18     print("
    {:^3.0f}%[{}->{}]{:.2f}s".format(c,a,b,dur))
    19 time.sleep(0.1)
    20 Pi=k
    21 print("Pi值是{}".format(Pi))
    22 print("
    "+"执行结束".center(scale//2,'-'))

    进度条覆盖进行:

     1 import math
     2 import time
     3 scale=50
     4 s,m,=1,2
     5 total,s,n,t=0.0,1,1.0,1.0
     6 print("执行开始".center(scale//2, "-"))
     7 start = time.perf_counter()
     8 for i in range(scale+1):
     9     total+=t
    10     n+=2
    11     s=-s
    12     t=s/n
    13     k=total*4
    14     a = '*' * i 
    15     b = '.' * (scale - i)
    16     c = (i/scale)*100 
    17     dur = time.perf_counter() - start 
    18     print("
    {:^3.0f}%[{}->{}]{:.2f}s".format(c,a,b,dur),end='')
    19     time.sleep(0.1)
    20 Pi=k
    21 print("Pi值是{}".format(Pi))
    22 print("
    "+"执行结束".center(scale//2,'-'))

  • 相关阅读:
    HtmlAgilityPack
    随笔-20150513
    过滤掉html 标签
    json转换
    第28月第3天 c语言读写文件
    第27月第28天 iOS bundle
    第27月第27天 https
    第27月第25天 clang -rewrite-objc main.m
    第27月第24天 git pull fetch
    第27月第18天 epoll lt et
  • 原文地址:https://www.cnblogs.com/LSH1628340121/p/12590139.html
Copyright © 2011-2022 走看看