CampusX SDE Sheet | Write a function that accepts a number and returns it’s factorial

Write a function that accepts a number and returns it’s factorial. You can not use any loop

Write a function that accepts a number and returns it’s factorial.



'''
Write a function that accepts a number and returns it’s factorial. You can not use any loop
'''

def factorial(n):
    if n==0:
        return 1
    else:
        return n * factorial(n-1)
    
print(factorial(5))

Post a Comment

Previous Post Next Post