For21. An integer N (>0) is given. Using one cycle, find the sum
\(1 + 1/(1!) + 1/(2!) + 1/(3!) + ... + 1/(N!)\)
(The expression N! - N-factorial - denotes the product of all integers from 1 to N: \(N! = 1 \cdot 2 \cdot ... \cdot N\)). The resulting number is an approximate value of the constant e = exp(1).

Solution in Python 3:

import random
import math
N = random.randrange(1,15)
N = 20
print('N = ', N)

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