For22. Real number X and an integer N (>0) are given. Find the value of expression
\(1 + X + X^2/(2l) + ... + X^N/(N!)\)
(\(N! = 1 \cdot 2 \cdot ... \cdot N\)). The resulting number is an approximate value of the function exp at the point X.

Solution in Python 3:

import math
X = 2
N = 20
print('X = ', X)
print('N = ', N)

F = 1.0
S = 1.0
for i in range(1,N+1):
F *= X / i
S += F
print(i," : ", F," : ", S)
print("Result:")
print(S)
print("e:")
print(math.exp(X))