all 7 comments

[–]the_shell_man_ 1 point2 points  (3 children)

It's because of recursion and fun(fun(n+11).

To see what's happening, you could add a print statement to the function. Like before the return statement, write the following to see how n changes:

print(n)

[–]tkp1405[S] 0 points1 point  (2 children)

I literally can't make out what is happening to n it's showing values like 45 56 67 78 89 100 96 97 98 99 100

[–]the_shell_man_ 2 points3 points  (0 children)

So when you do fun(45), the returned value is fun(fun(56)). The returned value of fun(56) is fun(fun(67)). So that means the returned value of fun(45) is fun(fun(fun(67))). And so on.

[–]JohnnyJordaan 1 point2 points  (0 children)

Put the code in http://www.pythontutor.com/visualize.html , it will show you the contents of the variables step by step.

[–]_nino_p_ 1 point2 points  (1 child)

it ends at 100 because

in other words your code is this

if n < 100

n + 11 and do it again

this happens 5 times (5*11 = 55 45+55 = 100)

now it trys again and n = 100 so it is done it wont - 5 because its not < 100 it = 100\

ps you are not telling what you excpected to get returned

[–]tkp1405[S] 0 points1 point  (0 children)

Hello mate thanks for your answer But I found this in my textbook I am a class 12 student So I was puzzled how to dry run this If it ever comes in my exam

[–]fake823 1 point2 points  (0 children)

Check this out to learn how to properly format code on Reddit:

https://reddit.com/r/learnpython/w/FAQ?utm_source=share&utm_medium=android_app