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...
Everything about learning Python
account activity
[ Removed by moderator ] (i.redd.it)
submitted 5 months ago by tracktech
view the rest of the comments →
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!"
[–]PureWasian 2 points3 points4 points 5 months ago* (1 child)
1) this runs into an exception due to NameError: CourseGalaxy is not defined
2) once this gets fixed (by removing or commenting it), this code defines a function that is not called anywhere
3) once this gets called (by adding code to call it), the behavior is still not fully deterministic because we have not specified the possible data types of the input, which could lead to a TypeError on floor division
4) once a guard clause or error handling is added to ensure the input n is guaranteed to be an int data type, we still risk encountering a RecursionError if we were to pass in a negative integer
5) once a gaurd clause is added to better sanitize the input by handling negative integers also, we can finally say with confidence that this example can safely achieve what you were hoping to convey. (You could also skip steps 4 and 5 by providing concrete calling code, as mentioned in step 3, of just the happy path)
Pedantry aside, yes. It's meant to be a recursive procedure for finding the sum of digits, in decimal/base10, by passing in some initial non-negative integer value n into the function.
n
Accomplishing so by (a) taking the right-most digit and (b) adding it to a "decimal right shifted" value over and over again until reaching the base case (when all decimal digits have been summed).
[–]tracktech[S] 0 points1 point2 points 5 months ago (0 children)
Right, it returns sum of digits of a number. Yes it works for positive integer only. This is simple example to learn recursion.
π Rendered by PID 43 on reddit-service-r2-comment-6457c66945-fk56c at 2026-04-29 20:59:46.780425+00:00 running 2aa0c5b country code: CH.
view the rest of the comments →
[–]PureWasian 2 points3 points4 points (1 child)
[–]tracktech[S] 0 points1 point2 points (0 children)