Factorial of a number
To find the factorial of a given number by defining a function
A factorial is the product of all the integers from 1 to that number.
In this code, we use the concept of a recursive function, that is, the functions are called multiple times while executing it once.
Note: Loved the post? You too can publish your article on “Python for fun” which will be loved by millions. Contribute an article!
def factorial(n): if n <= 0: return(1) else: val=n*factorial(n-1)#Since n!=n*(n-1)! return(val) m=input("Enter a number")#taking input from user num=int(m)#By default, the input is considered to be a string. so we convert it into an integer print(factorial(num))