[Python] python自定义pi函数 →→→→→进入此内容的聊天室

来自 , 2019-06-14, 写在 Python, 查看 101 次.
URL http://www.code666.cn/view/c42af2fa
  1. def pi():
  2.     # Compute digits of Pi.
  3.     # Algorithm due to LGLT Meertens.
  4.     k, a, b, a1, b1 = 2, 4, 1, 12, 4
  5.     while 1:
  6.         p, q, k = k*k, 2*k+1, k+1
  7.         a, b, a1, b1 = a1, b1, p*a+q*a1, p*b+q*b1
  8.         d, d1 = a//b, a1//b1
  9.         while d == d1:
  10.             yield d
  11.             a, a1 = 10*(a%b), 10*(a1%b1)
  12.             d, d1 = a//b, a1//b1
  13. #//python/2393

回复 "python自定义pi函数"

这儿你可以回复上面这条便签

captcha