国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

基于Python計(jì)算圓周率pi代碼實(shí)例

瀏覽:3日期:2022-08-01 10:36:11

一 計(jì)算公式:

基于Python計(jì)算圓周率pi代碼實(shí)例

二 實(shí)現(xiàn)代碼

(1)

import mathfrom tqdm import tqdmimport timetotal,s,n,t=0.0,1,1.0,1.0while(math.fabs(t)>=1e-6): total+=t n+=2 s=-s t=s/nk=total*4print('π值是{:.10f} 運(yùn)行時(shí)間為{:.4f}秒'.format(k,time.clock()))for i in tqdm(range(101)): print('r{:3}%'.format(i),end='') time.sleep(0.1)

(2)

import timeimport math class Index(object): def __init__(self, number=50, decimal=2): self.decimal = decimal self.number = number self.a = 100/number def __call__(self, now, total): percentage = self.percentage_number(now, total) well_num = int(percentage / self.a) progress_bar_num = self.progress_bar(well_num) result = 'r%s %s' % (progress_bar_num, percentage) return result def percentage_number(self, now, total): return round(now / total * 100, self.decimal) def progress_bar(self, num): well_num = '#' * num space_num = ' ' * (self.number - num) return ’[%s%s]’ % (well_num, space_num)index = Index()total,s,n,t=0.0,1,1.0,1.0while(math.fabs(t)>=1e-6): total+=t n+=2 s=-s t=s/nk=total*4start = 371for i in range(start + 1): print(index(i, start), end=’’) time.sleep(0.01)print('n π值是{:.10f}'.format(k))

(3)

import timeimport mathtotal,s,n,t=0.0,1,1.0,1.0while(math.fabs(t)>=1e-6): total+=t n+=2 s=-s t=s/nk=total*4scale=50print(''.center(scale//2,'-'))start = time.perf_counter()for i in range(scale+1): a='*'*i b='.'*(scale-i) c=(i/scale)*100 d=time.perf_counter() - start print('r{:^3.0f}%[{}->{}]{:.2f}s'.format(c,a,b,d),end=’’) time.sleep(0.1)print('n π值是{:.10f}'.format(k))

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。

標(biāo)簽: Python 編程
相關(guān)文章:
主站蜘蛛池模板: 万宁市| 嘉兴市| 重庆市| 长葛市| 汉寿县| 同仁县| 新蔡县| 锡林郭勒盟| 石城县| 丹巴县| 尉犁县| 本溪市| 杭锦后旗| 河津市| 新建县| 阿拉善盟| 石泉县| 岱山县| 宽城| 彰化市| 西和县| 岳阳县| 开化县| 西城区| 酒泉市| 玉山县| 白山市| 阿巴嘎旗| 嘉黎县| 嵊州市| 威宁| 永新县| 民和| 老河口市| 克拉玛依市| 安宁市| 光泽县| 新晃| 夏河县| 江油市| 隆尧县|