Dec-02-2020, 05:30 PM
Greetings,
I have a recursive function that I ran through the debugger in PyCharm and I am having a difficult time making sense of some of it. Here is the function in question:
Can someone help me understand why this is happening?
Thank You,
Matt
I have a recursive function that I ran through the debugger in PyCharm and I am having a difficult time making sense of some of it. Here is the function in question:
def rec_count(number):
print(number)
# Base case
if number == 0:
return 0
rec_count(number - 1)
print(number) #After recursion meets base case it then moves on to this print statement.
#When I step into this print statement, it is printing out the numbers in reverse.
#What I don't understand is, how can a print statement loop through this number variable?
rec_count(5)Read the comments to understand my problem. The function prints out the following. Output:5
4
3
2
1
0
1
2
3
4
5When it hits the last print statement, how is it looping through the number variable? It is not a loop but it is acting like one.Can someone help me understand why this is happening?
Thank You,
Matt
