Python pi calculation?
问题 I am a python beginner and I want to calculate pi. I tried using the Chudnovsky algorithm because I heard that it is faster than other algorithms. This is my code: from math import factorial from decimal import Decimal, getcontext getcontext().prec=100 def calc(n): t= Decimal(0) pi = Decimal(0) deno= Decimal(0) k = 0 for k in range(n): t = ((-1)**k)*(factorial(6*k))*(13591409+545140134*k) deno = factorial(3*k)*(factorial(k)**3)*(640320**(3*k)) pi += Decimal(t)/Decimal(deno) pi = pi * Decimal