Python program to find the factorial of a given number
Write a Python program to accept a number from the user, find and display the factorial of a given number.
Let the user has entered a number say 5. Then factorial of 5 is calculated using the below formula.
num = 5
fact = 5 * 4 * 3 * 2 * 1 = 120
First set the value of fact to 1. Then read a number from a user using the input statement. Next, until the value of a number is greater than 0, multiply the factorial with the number and decrement the value of a number by 1.
Source code of Python program to find the factorial of a number
fact = 1 num = int (input("Enter the number: ")) org = num while num > 0: fact = fact * num num = num - 1 print ("The factorial of ", org ," is ", fact)
Enter the number: 15
The factorial of 15 is 1307674368000
Enter the number: 5
The factorial of 5 is 120
This tutorial discusses how to write a program to find the factorial of a given number d and its length. If you like the tutorial share it with your friends. Like the Facebook page for regular updates and YouTube channel for video tutorials.