Skip to content

Instantly share code, notes, and snippets.

@ayubmetah
Created December 20, 2020 01:16
Show Gist options
  • Save ayubmetah/6c35318a1c68f7346632629c6100055e to your computer and use it in GitHub Desktop.
Save ayubmetah/6c35318a1c68f7346632629c6100055e to your computer and use it in GitHub Desktop.
An example of recursion in Python at work
#recursions example-2
def factorial(n):
print("Factoriaal called with " + str(n))
if n < 2:
print("Returning 1")
return 1
result = n * factorial(n - 1)
print("Returning " + str(result) + " for factorial of " + str(n))
return result
factorial(4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment