Table of Contents
Introduction
In this section of python coding, we’ll learn how to find the factorial of a given number. A factorial of number n is the multiplication of all the numbers equals and smaller than the given number n.
Let’s look into the python coding to find the factorial of the given number.
Program
def fact(f): return 1 if (f==1 or f==0) else f * fact(f - 1) num = 6 n = fact(num) print("Factorial of {0} is {1}".format(num,n))
Output
Explanation
In the above code we have created a recursive function fact() which will return the factorial of number. The resultant factorial is saved in variable n and is displayed through print() function.
0 Comments