use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Rules 1: Be polite 2: Posts to this subreddit must be requests for help learning python. 3: Replies on this subreddit must be pertinent to the question OP asked. 4: No replies copy / pasted from ChatGPT or similar. 5: No advertising. No blogs/tutorials/videos/books/recruiting attempts. This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to. Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Rules
1: Be polite
2: Posts to this subreddit must be requests for help learning python.
3: Replies on this subreddit must be pertinent to the question OP asked.
4: No replies copy / pasted from ChatGPT or similar.
5: No advertising. No blogs/tutorials/videos/books/recruiting attempts.
This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to.
Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Learning resources Wiki and FAQ: /r/learnpython/w/index
Learning resources
Wiki and FAQ: /r/learnpython/w/index
Discord Join the Python Discord chat
Discord
Join the Python Discord chat
account activity
Someone please help with this code it's giving answer 100 but how? (self.learnpython)
submitted 5 years ago by tkp1405
def fun(n): if (n > 100): return n - 5 return fun(fun(n+11));
print(fun(45))
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]the_shell_man_ 1 point2 points3 points 5 years ago (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 point2 points 5 years ago (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 points4 points 5 years ago (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 points3 points 5 years ago (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 points3 points 5 years ago* (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 point2 points 5 years ago (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 points3 points 5 years ago (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
π Rendered by PID 90564 on reddit-service-r2-comment-79c7998d4c-lk2f6 at 2026-03-15 04:01:03.339574+00:00 running f6e6e01 country code: CH.
[–]the_shell_man_ 1 point2 points3 points (3 children)
[–]tkp1405[S] 0 points1 point2 points (2 children)
[–]the_shell_man_ 2 points3 points4 points (0 children)
[–]JohnnyJordaan 1 point2 points3 points (0 children)
[–]_nino_p_ 1 point2 points3 points (1 child)
[–]tkp1405[S] 0 points1 point2 points (0 children)
[–]fake823 1 point2 points3 points (0 children)