Python Program to Find the Factorial of a Number
In this example, we will write a simple program to take input number from the user and display the factorial of the number. To better understand this example, make sure you have knowledge of the following tutorials:-
The factorial of a positive integer n, denoted by n!, is the product of all positive integers less than or equal to n.
Python Program to Find the Factorial of a Number
number = int(input("Enter a number: ")) if number < 0: print("Factorial doesn't exists for negative number !!!") elif number == 0: print("The factorial of 0 is 1") else: factorial = 1 for i in range(1, number + 1): factorial *= i print("The factorial of", number, "is", factorial)
The output of the above program is:-
Enter a number: 5
The factorial of 5 is 120
The factorial of 5 is 120