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)

python求圆周率Π

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求圆周率Π

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-05
  • 2022-01-26
  • 2021-07-06
  • 2021-12-10
猜你喜欢
  • 2021-09-17
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-27
  • 2022-12-23
相关资源
相似解决方案