ulvis.paste.net

Paste Search Dynamic
Recent pastes
factorial
  1.  
  2. def recur_factorial(n):
  3.    """Function to return the factorial
  4.   of a number using recursion"""
  5.    if n == 1:
  6.        return n
  7.    else:
  8.        return n*recur_factorial(n-1)
  9.  
  10. # Change this value for a different result
  11. num = 7
  12.  
  13. # uncomment to take input from the user
  14. #num = int(input("Enter a number: "))
  15.  
  16. # check is the number is negative
  17. if num < 0:
  18.    print("Sorry, factorial does not exist for negative numbers")
  19. elif num == 0:
  20.    print("The factorial of 0 is 1")
  21. else:
  22.    print("The factorial of",num,"is",recur_factorial(num))
Parsed in 0.007 seconds