approx = 0
for i in range(1,20):
term = 1/2**i
approx = approx + term
print(approx)
0.9999980926513672
approx = 0
for i in range(0,100000):
term = (-1)**i * (1/(2*i+1))
approx = approx + term
print(approx)
0.7853956633974299
import math
math.pi/4
0.7853981633974483
from math import factorial
approx = 0
x_str = input('Enter a number')
x = float(x_str)
for i in range(10):
term = ((-1)**i) * ((x**(2*i+1)) / (factorial(2*i+1) ))
#approx = approx + term
approx += term
print(approx)
Enter a number1.57079 0.9999999999799855
math.sin(1.57079)
0.9999999999799858