#Use a for loop to calculate the value of 1, using a numerical method
n=0
for i in range(1,5):
n = n + 1/2**i
print(f'The approx value of n is {n}')
n=0
for i in range(1,10):
n = n + 1/2**i
print(f'The approx value of n is {n}')
n=0
for i in range(1,10000):
n = n + 1/2**i
print(f'The approx value of n is {n}')
The approx value of n is 1.0
n = 0
for i in range(0,3):
term = (-1)**i / (2*i+1)
n = n + term
print(f'The approx value of pi/4 is {n}')
The approx value of pi/4 is 0.8666666666666667
import math
print(math.pi/4)
0.7853981633974483
n = 0
for i in range(0,10):
term = (-1)**i / (2*i+1)
n = n + term
print(f'The approx value of pi/4 is {n}')
The approx value of pi/4 is 0.7604599047323508
n = 0
for i in range(0,10000):
term = (-1)**i / (2*i+1)
n = n + term
print(f'The approx value of pi/4 is {n}')
The approx value of pi/4 is 0.7853731633975086