Calculate factorial using recursion in python

GOCOURSE

Factorial using recursion :

Program:


  print("program to calculate factorial of a number")
  num=int(input("Enter the number"))
  def fact(num):
      if(num<1):
          print("Enter only positive values")
          exit()
      elif(num==1):
          return num
      else:
          return num*fact(num-1)
  print(fact(num)) 


Output:


  program to calculate factorial of a number
  Enter the number5
  120


Our website uses cookies to enhance your experience. Learn More
Accept !

GocourseAI

close
send