在Python中如何计算圆周率呢?下面是详细的代码和运行结果:
如下图是详细的计算圆周率的代码:
importmath importtime scale=10 print("执行开始") t=time.process_time() foriinrange(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("执行结束")
下图是代码运行结果:
原文来自:https://www.py.cn© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END
暂无评论内容