首页 > 编程语言 > 详细

用python计算圆周率

时间:2020-03-23 00:42:13      阅读:55      评论:0      收藏:0      [点我收藏+]

import math
import time
scale=14 #scale的值越大,π的值越精确,但运算时间会加长
s,m,=1,2
total,s,n,t=0.0,1,1.0,1.0
print("执行开始".center(scale//2, "-"))
start = time.perf_counter()
for i in range(scale+1):
total+=t
n+=2
s=-s
t=s/n
k=total*4
a = ‘*‘ * i
b = ‘.‘ * (scale - i)
c = (i/scale)*100
dur = time.perf_counter() - start
print("\r{:^3.0f}%[{}->{}]{:.2f}s".format(c,a,b,dur))
time.sleep(0.1)
Pi=k
print("Pi值是{}".format(Pi))
print("\n"+"执行结束".center(scale//2,‘-‘))

用python计算圆周率

原文:https://www.cnblogs.com/dongchidachi/p/12549493.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!