add recursion

This commit is contained in:
onyx-and-iris 2024-01-07 17:57:58 +00:00
parent 5b6a20dedf
commit 3a138acf93

7
chapter3/recursion.py Normal file
View File

@ -0,0 +1,7 @@
def factorial(x):
if x == 1: # This is the base case
return 1
return x * factorial(x - 1) # This is the recursive case
print(factorial(4))