Write a Python Program to find the factorial of a number using recursion

Write a Python Program to find the factorial of a number using recursion

Program

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

if __name__=="__main__":
    num =int(input("Enter Number : "))
    if num < 0:
        print("Sorry, factorial does not exist for negative numbers")
    elif num == 0:
        print("The factorial of 0 is 1")
    else:
        print("The factorial of",num,"is",factorial(num))




Output:

Enter Number : 5
The factorial of 5 is 120


More Questions


28 . Write a Python Program to find the factorial of a number using recursion
29 . Write a Python Program to check armstrong number of n digits
30 . Write a program to check armstrong numbers in certain interval
31 . Write a program to merging dictionaries
32 . Write a program to print swapping variables
33 . Write a python program to counting item occurrences
34 . Write a python program to print flatten a nested list
35 . Write a python program to Find the index of the largest number in the list
36 . Write a python program to Find the index of the smallest number in the list
37 . Write a python program to find absolute value of a number in the list
38 . Write a python program to adding a thousand separator