Programming Blog

This blog is about technical and programming questions and there solutions. I also cover programs that were asked in various interviews, it will help you to crack the coding round of various interviews

Wednesday 20 December 2017

Python program to find factorial of a number

# Python program to find the factorial of a number using recursion


def  factorial(n):   """Function"""


   if n == 1:       return n   

else:      

 return n*factorial(n-1)



num = int(input("Enter a number: "))
# check is no is negative

num < 0: 

  print("sorry ")

elif num == 0:   

print("The factorial of 0 is 1")

else:   

print("The factorial of",num,"is",factorial(num))

No comments:

Post a Comment