Hello amigos! we are here to see about how to create a python program to find the factorial of a random number.
WHAT IS A FACTORIAL
In mathematics, the product of all positive integers less than or equal to a given positive integer and denoted by that integer and an exclamation point. Thus, factorial seven is written 7!, meaning 1 × 2 × 3 × 4 × 5 × 6 × 7=5040.
Firstly we should declare a user-defined function of any name(here the function name is factorial).This a recursive function which call itself again and again.Then using if statement declare a condition if num==1 then return num.Here the num is the user’s input.
It is used because factorial of 1 is equal to 1.
Now we have to get the number which we have to calculate the factorial for the user.Get the input as an integer.Now with the help of if and elif check whether the input is less than or equal to 0.
If the input is less than zero,then print that factorial number cannot be found
If the input is equal to zero,then print 1.Since factorial of 0 is 1.
Now in the else statement,with the help of ‘factorial’ function print the factorial number.Since we built the function with set of codes to find the factorial number it would calculate accordingly.
COMPLETE CODE:
OUTPUT:


Thank you!
For more details sign in @www.guvi.com