Factorial of a number in Python

Share on facebook
Share on twitter
Share on pinterest

In this Basic Python Program, we will find the factorial of a number.

What is factorial of a number?

In Mathematics, Factorial of a non-negative integer is multiplication of all integers smaller than or equal to n.

Example: factorial of 3 will be 3*2*1, that will be 6.

Python Program To Find The Factorial Of A Number

def factorial_num(n): 
     return 1 if (n==1 or n==0) else n * factorial_num(n - 1); 
 num = 3; 
 print("Factorial of",num,"is", 
 factorial_num(num)) 

Output:

Factorial of 3 is 6

Subscribe to our Newsletter

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo.

Share this post with your friends

Share on facebook
Share on google
Share on twitter
Share on linkedin

Leave a Reply

Your email address will not be published. Required fields are marked *