python123作业:Π的计算

import time
pi = 0
n = 100
print("第一种进度条:")
t = 60
print("**************带时间的进度条**************")
start = time.perf_counter()
for i in range(t + 1):
    finsh = "▓" * i
    need_do = "-" * (t - i)
    progress = (i / t) * 100
    dur = time.perf_counter() - start
    print("\r{:^3.0f}%[{}->{}]{:.2f}s".format(progress, finsh, need_do, dur), end="")
    if i<100:
        pi += 1 / pow(16, i) * (4 / (8 * i+ 1) - 2 / (8 * i + 4) - 1 / (8 * i + 5) - 1 / (8 * i + 6))
    time.sleep(0.05)
print("\n第二种进度条:")
from tqdm import tqdm
for i in tqdm(range(1, 60)):
    """
    if i<100:
         pi += 1 / pow(16, i) * (4 / (8 * i+ 1) - 2 / (8 * i + 4) - 1 / (8 * i + 5) - 1 / (8 * i + 6))
    """
    time.sleep(0.05)
print("\n圆周率PI是:{}".format(pi))
print("计算圆周率PI的具体公式是:pi += 1/pow(16, k) * (4 / (8 * k + 1) - 2 /(8 * k + 4) - 1/(8 * k + 5) - 1 /(8 * k + 6))")

posted @ 2023-10-25 22:09  599Y  阅读(132)  评论(0)    收藏  举报