def factorial(num): """This is a recursive function that calls itself to find the factorial of given number""" if num == 1: return num else: return num * factorial(num - 1) # We will find the factorial of this number num = int(input("Enter a Number: ")) # if input number is negative then return an error message # elif the input number is 0 then display 1 as output # else calculate the factorial by calling the user defined function if num < 0: print("Factorial cannot be found for negative numbers") elif num == 0: print("Factorial of 0 is 1") else: print("Factorial of", num, "is: ", factorial(num))
Enter a Number: 16 Factorial of 16 is: 20922789888000