Write a Python function to calculate the factorial of a number


example:1
def factorial(num):
    if num == 0:
        return 1
    else:
        return num * factorial(num-1)
num=int(input("Input a number to compute the factiorial : "))
print(factorial(num))

output:-
Input a number to compute the factiorial : 5
120
>>> 

example 2:

import math

def factorial(n):
	return(math.factorial(n))

num = 5
print("Factorial of", num, "is",
	factorial(num))


output:
Factorial of 5 is 120
>>> 

Post a Comment

If you have any doubts, Please let me know
Thanks!

Previous Post Next Post