重点:
import math
def factorial(k):
result = 1
while k >= 1:
result *= k
k -= 1
return result
k = 0
sum = 0
while k <= 15:
a = factorial(4*k)
b = 1103 + 26390*k
c = (factorial(k))**4
d = 396**(4*k)
sum += a*b/c/d
k += 1
ans = (2*(2**0.5))/9801*sum
ans = 1/ans
print "My answer: %.15f"%ans
print "math.pi: ",math.pi
运算结果
My answer: 3.141592730013306
math.pi: 3.14159265359