def factorial(n): if n == 1: return n else: return n*factorial(n-1) if __name__=="__main__": num =int(input("Enter Number : ")) 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",factorial(num))
Enter Number : 5
The factorial of 5 is 120