python-模拟math.pi
来源:互联网 发布:淘宝静物拍摄怎么做 编辑:程序博客网 时间:2024/06/07 16:50
编写循环控制代码用下面公式逼近圆周率(精确到小数点后15位),并且和math.pi的值做比较。
重点:
- 阶乘写成一个函数更加方便使用
import mathdef factorial(k): result = 1 while k >= 1: result *= k k -= 1 return resultk = 0sum = 0while k <= 15: a = factorial(4*k) b = 1103 + 26390*k c = (factorial(k))**4 d = 396**(4*k) sum += a*b/c/d k += 1ans = (2*(2**0.5))/9801*sumans = 1/ansprint "My answer: %.15f"%ansprint "math.pi: ",math.pi运算结果My answer: 3.141592730013306math.pi: 3.14159265359
1 0
- python-模拟math.pi
- PI模拟数据配置
- 蒙特卡洛模拟计算PI
- 关于 Math 中对 PI 的引用
- 关于 Math 中对 PI 的引用
- Raspberry Pi I2C (Python)
- Raspberry Pi+Python+ GPIO
- Raspberry Pi + Python + Serial
- 【NOIP模拟】Math
- [NOIP2017模拟]Math
- [NOIP模拟] Math
- javascript对象小探之一——Math.PI
- 使用Java Math.random()利用蒙特卡洛方法计算pi值
- 树莓派 raspberry pi GPIO python
- Python, Crawler and Raspberry Pi
- 【NOI2014模拟7.11】数学题(math)
- NOIP模拟 Math 【同余】
- [NOIP模拟][数学推理]Math
- 对一个正整数n,算得到1需要的最少操作次数
- python线程池(threadpool)模块使用
- animation中的transform
- zoj3872Beauty of Array
- POJ-3071 Football (概率DP)
- python-模拟math.pi
- leetcode:25. Reverse Nodes in k-Group
- linux常用命令-part1
- case when 将表中一列按照一定规则分两列显示
- linux常用命令-part2
- 搜索水题 (排列组合)
- Ubuntu16.04 VirtualBox的卸载和升级
- JSP与Servlet中的相对路径与绝对路径问题
- Python运维自动化--nginx配置文件对比