ITPub博客

首页 > IT职业 > IT图书 > 如何用python求圆周率?

如何用python求圆周率?

IT图书 作者:daxuesheng 时间:2021-09-11 10:16:45 0 删除 编辑

在Python中如何计算圆周率呢?下面是详细的代码和运行结果:

如下图是详细的计算圆周率的代码:

import math
import time
scale = 10
print("执行开始")
t=time.process_time()
for i in range(scale+1):
a,b = '**'*i,'|..'*(scale-1)
c = (i/scale)*100
π = 4*(4*math.atan(1/5)-math.atan(1/239))
print("%{:3}[{}->{}".format(a,b,c))
time.sleep(0.1)
print(π)
print("{:.2f}s".format(t))
print("执行结束")

下图是代码运行结果:

p1.jpg

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/4692/viewspace-2833646/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-05-22

  • 博文量
    176
  • 访问量
    24986