0
Help with user define functions.
def num(n): if n<=0: return else: print (n) num(n-1) print('******') print(n) num(4) The first print(n) statement inside else will print values of n but why do i get values for second print statement inside else, even when n==0 then else is not going to run. But still i get the values of n. Why?
2 Answers
+ 5
Abdur Raheem ,
your code has a recursively call of the function num(). i am not sure if this is what your code should do or if it is by accident.
to understandthe the low of this code, you should run your code in a debugger step by step. one of them is "pythontutor". copy your code and paste it in the code editor of this website. then click "visualize execution"
to step through the code click "next".
https://pythontutor.com/visualize.html#mode=edit
0
Thanks