Data x real and n natural, compute an approximation for cos x through n first terms of the following series:
cos x = 1/1 - (x**2)/2! + (x**4)/4! - (x**6)/6! + ... + ((-1)**k)*(x**2k)/((2k)!)
My attempt to resolve:
import math
#x =1 #calcular o cosx
#k =1 #número de termos da série
k = int(input("Digite k: "))
x = float(input("Digite x: "))
soma =0.0
for i in range(0,k+1):
soma += ((-1)**k)*(x**(2*k))/(math.factorial(2*k))
print(soma)
What is the implementation error? How to correct?