Python计算π值-麦克劳林公式

环境准备

运行平台: Windows 7  旗舰版
Python版本: Python 3.6.4
IDE: Pycharm 2019.2.3
计算原理

麦克劳林公式:

实现代码

# coding=utf-8my_pi = 2i = 1000while i > 0:    my_pi = my_pi * i / (2 * i + 1) + 2    i -= 1print(my_pi)

注:i值越大,求出的π值越精确

THE END