For24. A real number X and an integer N (>0) are given. Find the value of expression
\(1 - X^2/(2!) + X^4/(4!) - ...  + (-1)^N \cdot X^{2 \cdot N}/((2 \cdot N)!)\)
(\(N! = 1 \cdot 2 \cdot ... \cdot N\)). The number obtained is an approximate value of the function cos at the point X.

Solution in Python 3:

import math
X = math.pi/3
N = 10
print('X = ', X)
print('N = ', N)

p = 1
S = 1
k = 1
for i in range(1,N+1):
p *= (-1) * X * X / (k * (k + 1))
S += p
print(i," : ", k," : ", k+1," : ", p," : ", S)
k += 2
print("Result:")
print(S)
print("cos:")
print(math.cos(X))