Python program to find Factorial of a given number

Hello people, I am back here to discuss how to find the factorial of a given number.

Generally, a factorial on a given number is given by calculating its product with all the numbers below it.

Factorial is represented as !

For Example : 4! = 4 * 3 * 2 * 1 = 24

Master the basics of data analysis in Python. Expand your skillset by learning scientific computing with numpy.

Take the course on Introduction to Python on DataCamp here

Program on Github

Task :

To find factorial of a given number.

Approach :

  • Read the input number for which the factorial is to be found using input() or raw_input().
  • Check whether the input number is negative and show an appropriate message
  • If the number entered is 0, print factorial as 1
  • When the entered number is a positive integer and greater than 1, initialize a variable factorial as 1 then run a for loop from 1 to the number+1
  • Calculate the factorial as factorial * i
  • Print the result

Program on Github

Factorial – Code Visualization

Program :

Output :

Factorial of a given number -
Factorial of a given number –

Program on Github

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.