Python 3 Program To Find The Factorial Of A Number

Here you will learn a simple Python 3 program to find the factorial of a number. Before moving ahead, make sure that you have a basic knowledge of Python programming language concepts such as syntax, variables, if-else statements, and for loops. In case you are looking for an excellent book to learn Python, then check out our list of recommended Python books for beginners.

Python 3 Program To Find The Factorial Of A Number

To calculate the factorial of a number, you first have to take input from the user and then check if the number is positive or negative. If the number is positive, you can use the for loop to calculate the factorial of that number. Check out this self-explanatory Python code.

fact = 1
num = int(input("enter the number"))
if num < 0:
   print("Enter a +ve number")
elif num == 0:
   print("0 factorial =1")
else:
   for i in range(1, num + 1):
       fact = fact * i
print("Factorial of", num, "=", fact)

Output

Enter the number: 4
Factorial of 4 = 24

output - python program -factorial of number

Download this Python program.

Try it yourself

Related Examples:

  1. Python 3 Program to Check Leap Year.
  2. Python 3 Program To Convert Celsius To Fahrenheit.
  3. Python 3 Program To Find Largest Element In An Array or List.
  4. Python 3 Program To Find The Sum of An Array.
  5. Python 3 Program to Convert Kilometers to Miles.
  6. Python 3 Program to Generate A Random Number.
  7. Python 3 Program To Swap Two Numbers.
  8. Python 3 Program To Solve A Quadratic Equation.
  9. Python 3 Program to Calculate The Area of a Triangle.
  10. Python 3 Program to Find the Square Root of A Number.

Scroll to Top