Write the recursive version of the factorial calculation upto a number n

def recur_factorial(num):

       if num == 1:

         return num

       else:

         return num * recur_factorial(num - 1)

num = int(input("enter the number to check the factorial:"))

# check if the number is negative

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", recur_factorial(num))



output

enter the number to check the factorial ;6

the factorial of 6 is 720

Comments