Python Online Compiler

Python Compiler

# Factorial of a Number using Recursion

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

num = 7

# 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_fact(num))