Recursive Factorial

    0

    1

    Mahendra Kumar

    beginnerrecursionbasicMaths

    Finding Factorial of a given number using recursion.

    def recur_factorial(n):  #user-defined function
       if n == 1:
           return n
       else:
           return n*recur_factorial(n-1)
    # take input
    num = int(input("Enter number: "))
    # check number is positive, negative, or zero
    if num < 0:
       print('Factorial does not exist for negative numbers')
    elif num == 0:
       print('The factorial of 0 is 1')
    else:
        # calling function
        print('The factorial of',num,'is', recur_factorial(num))
    
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    Legal
    • Security
    • Privacy Policy
    • Code Privacy
    • Terms of Service
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.