Created
December 20, 2020 01:16
-
-
Save ayubmetah/6c35318a1c68f7346632629c6100055e to your computer and use it in GitHub Desktop.
An example of recursion in Python at work
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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