ganiyuisholaafeez

Recursion

Feb 20th, 2020
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.49 KB | None | 0 0
  1. """ This is a factorial function with an argument that returns the
  2. factorial of a supplied integer argument"""
  3. # The function has a base statement which the function returns to
  4. # to avoid looping
  5. def factorial(value):
  6.     if value == 1: # The base statement
  7.         return value
  8.     else:
  9.         return value * factorial(value - 1) # The function calling itself
  10.  
  11. # Function Invokation
  12. print(factorial(1))
  13. print(factorial(2))
  14. print(factorial(3))
  15. print(factorial(4))
  16. print(factorial(5))
Advertisement
Add Comment
Please, Sign In to add comment