Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Commit a0298d3

Browse files
Update pi.py
Took the "factor" term outside the braket of infinite summation so that they all have to be added only once
1 parent 9eba623 commit a0298d3

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

code/pi.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,14 @@ def estimate_pi():
3636
while True:
3737
num = factorial(4*k) * (1103 + 26390*k)
3838
den = factorial(k)**4 * 396**(4*k)
39-
term = factor * num / den
40-
total += term
39+
40+
total += num / den
41+
term = factor * num/den
4142

4243
if abs(term) < 1e-15:
4344
break
4445
k += 1
45-
46-
return 1 / total
46+
47+
return 1 / (factor * total)
4748

4849
print(estimate_pi())

0 commit comments

Comments
 (0)