Header Ads Widget

Python program to generate sum of series 1!+2!+3!+--------------n!

 

 Python program to generate sum of series 1!+2!+3!+--------------n! 

Given a number n , write a program to generate a sum of series 1!+2!+3!+--------------n! . For generating this first we have to know that how to find the factorial of a number . 

Program to find the factorial of a number  : -  Click here

Sample input

3

Sample output

Sum of the series is: 9

Explanation:

= 1! + 2! + 3!
=  1+2+6
=  9

Pyhton program to generate sum of series 1!+2!+3!+--------------n! 

The objective of the code is to generate sum of series 1!+2!+3!+--------------n!  .

Code(Python):-

def fact(n):
f=1
for i in range(1,n+1):
f=f*i
return f

n=int(input("Enter a number\n"))
sum=0
for i in range(1,n+1):
sum=sum+fact(i);
print(f"Sum of the series is: {sum}")

Output:-

Enter a number
3
Sum of the series is: 9


Recommended Post :-

HCL Coding Questions:-

Capgemini Coding Questions:-

Companies interview:-

Full C course:-    

Key points:-

Cracking the coding interview:-

 Array and string:-

Tree and graph:-

Hackerearth Problems:-

Hackerrank Problems:-

Data structure:-

 MCQs:-