Skip to content

Commit

Permalink
Merge pull request AllenDowney#90 from abhitrueprogrammer/patch-2
Browse files Browse the repository at this point in the history
Update pi.py
  • Loading branch information
AllenDowney authored Apr 10, 2022
2 parents 9eba623 + a0298d3 commit 8f3fc63
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions code/pi.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,14 @@ def estimate_pi():
while True:
num = factorial(4*k) * (1103 + 26390*k)
den = factorial(k)**4 * 396**(4*k)
term = factor * num / den
total += term

total += num / den
term = factor * num/den

if abs(term) < 1e-15:
break
k += 1

return 1 / total
return 1 / (factor * total)

print(estimate_pi())

0 comments on commit 8f3fc63

Please sign in to comment.