A Program to Find Factorial of a Number

In this example, we are giving a program to find the factorial of a number.


Program to find a factorial number:

  1. def factorial(n):
  2. # Single line to find factorial
  3. return 1 if (n==1 or n==0) else n * factorial(n - 1);
  4. num = 5
  5. print("Factorial of",num,"is"
  6. factorial(num))

Output:

Factorial of 5 is 120