Python factorial program with example

Spread the love

In this tutorial, you will learn how to write python factorial program. If you want calculate factorial of 5, you have to multiply values from 5 to 1 .

Example: 5! = 5*4*3*2*1

print("Python factorial program") num = int(input("Enter a number: ")) fact = 1 if num < 0: print("Sorry, factorial does not exist for negative numbers") elif num == 0: print("The factorial of 0 is 1") else: for i in range(1,num + 1): fact = fact*i print("The factorial of",num,"is",fact)

Output 1:

Python factorial program

Enter a number: 5
The factorial of 5 is 120

Output 2:

Python factorial program

Enter a number: 10
The factorial of 10 is 3628800

Output 3:

Python factorial program

Enter a number: 10
The factorial of 10 is 3628800

admin

admin

Leave a Reply

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