Skip to content

Commit 25a2fa9

Browse files
committed
add recursion
1 parent 9458c1e commit 25a2fa9

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/recursion1.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env python3
2+
3+
##
4+
# Recursion
5+
##
6+
7+
def recursion(i):
8+
"""
9+
This function demonstrates a simple recursive process. It prints the word "recursion" each time it is called,
10+
and increments the value of the parameter `i`. The recursion stops when `i` reaches 5.
11+
12+
Parameters:
13+
i (int): The current value that is incremented in each recursive call.
14+
15+
Returns:
16+
None: This function does not return any value, it only prints output to the console.
17+
"""
18+
print("recursion")
19+
i += 1
20+
if i == 5:
21+
return
22+
else:
23+
recursion(i)
24+
25+
# Initial call with value of i
26+
recursion(0)
27+
28+
29+

0 commit comments

Comments
 (0)