codescracker


python

Python Program to Find Factorial of Number



« Previous Program Next Program »


Find Factorial of Number in Python

To find factorial of any number in python, you have to ask from user to enter the number to find and print the factorial of that number on the output screen.

Python Programming Code to Find Factorial of Number

Following python program ask from user to enter a number to find the factorial of that number:

# Python Program - Find Factorial of a Number
		
while True:
	print("Enter 'x' for exit.")
	num = input("Enter a number: ")
	if num == 'x':
		break
	else:
		number = int(num)
		if number == 0:
			print("Factorial of 0 is 1\n")
		elif number < 0:
			print("Factorial of negative numbers doesn't exist..!!\n")
		else:
			fact = 1
			for i in range(1, number+1):
				fact = fact*i
			print("Factorial of", number, "is", fact, "\n")

Here is the sample run of the above Python program to demonstrate how to find factorial of a number:

python find factorial of number

Same Program in Other Languages

You may also like to learn or practice the same program in other popular programming languages:


« Previous Program Next Program »




Tools
Calculator

Quick Links
Signup - Login - Give Online Test