一品网
  • 首页

python求圆周率Π


蒙特卡洛方法求Π

import random
count = 0
for i in range(1000000):
    x, y = random.random(), random.random()
    dist = pow(x ** 2 + y ** 2, 0.5)
    if dist < 1:
        count += 1
print((count / 1000000)* 4)

pi = 0
k = 0
while True:

    pi +=  (1/(16**k))* \
          (4/(8*k+1) - 2/(8*k+4) - 1/(8*k+5) - 1/(8*k+6))

    print(pi)
    k += 1

Python基础

相关


python基础7 :数据类型、

python基础

python基础——3.文件操作&日志处理

Python基础学习篇(一)

python基础——1.编码,逻辑运算,转义字符,小数据池

Python基础 - 算数运算符

天池Python训练营笔记—Python基础入门:从变量到异常处理

Python基础 - 第一个python程序

(Python基础)简单购物车代码

python基础数据类型 列表(数组),字典(增删改查)

我的Python成长之路---第四天---Python基础(16)---2016年1月23日(寒风刺骨)

我的Python成长之路---第三天---Python基础(9)---2016年1月16日(雾霾)

标签

一品网 冀ICP备14022925号-6