repl.it
@sclanc20/

4.8. For: Sum of factorials

Python

No description

fork
loading
Files
  • main.py
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
"""
Instructions from your teacher:
Statement

In mathematics, the factorial of an integer n, denoted by n! is the following product:

n! = 1 × 2 × … × n

For the given integer n calculate the value 

1! + 2! + 3! + ... + n!

Try to discover the solution that uses only one for-loop. And don't use math module in this exercise.


Example input

4


Example output

33
"""
#PROGRAM:
n=int(input())
x=0
for i in range(1,n+1):
  y=1
  for j in range(1,i+1):
    y=y*j
  x=x+y  
print(x)
Fetching token
?