計算Π
一、寫代碼的准備工作:用pip下載第三方庫tqdm
1.打開cmd
2.輸入pip install 你要安裝的庫(如 pip install tqdm) #pip一般是在安裝python的時候就有了,還有tqdm我之前已經下載好了

二、寫程序
1.記憶中的C中的一道例題,正好提供一個算法

2.輸入以下代碼
from math import * from tqdm import tqdm from time import * total,s,n,t=0.0,1,1.0,1.0 clock() while(fabs(t)>=1e-6): total+=t n+=2 s=-s t=s/n k=total*4 print("π值是{:.10f} 運行時間為{:.4f}秒".format(k,clock())) for i in tqdm(range(100)): print("\r{:3}%".format(i),end="") sleep((clock())/100)

三、運行程序
1.過程一

2.運行最終結果如下

