无码av一区二区三区无码,在线观看老湿视频福利,日韩经典三级片,成 人色 网 站 欧美大片在线观看

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

計算圓周率代碼

2023-06-03 12:16 作者:星海三垣二十八宿  | 我要投稿

from tqdm import tqdm
import decimal
def pi_to_n_decimal_places(n):
? ?decimal.getcontext().prec = n + 1
? ?pi = decimal.Decimal(0)
? ?k = 0
? ?with tqdm(total=n + 1, desc="Processing pi calculation", leave=True) as progress:
? ? ? ?while True:
? ? ? ? ? ?term = 1 / decimal.Decimal(16) ** k * (
? ? ? ? ? ? ? ? ? ?decimal.Decimal(4) / (8 * k + 1) -
? ? ? ? ? ? ? ? ? ?decimal.Decimal(2) / (8 * k + 4) -
? ? ? ? ? ? ? ? ? ?decimal.Decimal(1) / (8 * k + 5) -
? ? ? ? ? ? ? ? ? ?decimal.Decimal(1) / (8 * k + 6))
? ? ? ? ? ?if abs(term) < decimal.Decimal("1e-{}".format(n)):
? ? ? ? ? ? ? ?break
? ? ? ? ? ?pi += term
? ? ? ? ? ?k += 1
? ? ? ? ? ?progress.update(1)
? ?return pi
pi = pi_to_n_decimal_places(1000000)
with open('圓周率.txt', 'w') as f:
? ?f.write(str(pi))
print('結果已保存在圓周率.txt文件中。')

不想部署環(huán)境的見以下鏈接

圓周率:https://aistudio.baidu.com/aistudio/projectdetail/6316403?contributionType=1&sUid=4115406&shared=1&ts=1685765459932


計算圓周率代碼的評論 (共 條)

分享到微博請遵守國家法律
华宁县| 专栏| 宜黄县| 宣威市| 鸡西市| 建阳市| 钟山县| 乐清市| 随州市| 巴彦淖尔市| 香河县| 共和县| 错那县| 梁河县| 彝良县| 华池县| 柞水县| 拉孜县| 莆田市| 颍上县| 林周县| 双桥区| 邛崃市| 射洪县| 呈贡县| 平武县| 大埔县| 台北县| 牡丹江市| 道孚县| 丹江口市| 塔城市| 岳池县| 龙南县| 武邑县| 常熟市| 库车县| 永城市| 名山县| 桦川县| 陕西省|