Files
  • main.py
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#ประมาณค่า π = 4(1 - 1/3 + 1/5 - 1/7...)
sum = 0.0
factor = 1
for k in range(0, 10000):
  sum = sum + factor/(2*k+1)
  factor = factor * (-1)
print(4 * sum)

#ประมาณค่า π = sqrt(12)(1 - 1/(3x3) + 1/(5x9) - 1/(7x27) ...)
import math
sum = 0.0
factor = 1.0
for k in range(0,20):
  sum = sum + factor/(2*k+1)
  factor = factor * (-1/3)
print(math.sqrt(12) * sum)
Python 3.6.1 (default, Dec 2015, 13:05:11) [GCC 4.8.2] on linux