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))
      
      Python language logo

      Recursive Factorial

      beginner
      recursion
      basicMaths

      Finding Factorial of a given number using recursion.

      0 Comments

        Add Comment

        Log in to add a comment

        Codiga - All rights reserved 2022.