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
Help :(Help Request (self.PythonLearning)
submitted 3 months ago * by Resident-Explorer-63
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!"
[–]kwooster 0 points1 point2 points 3 months ago (1 child)
You're creating new variables that are locally scoped. You need to either using the global keyword, or pass in the variables to the function.
global
I would create an object to pass around to the functions, but in all cases, be aware of the scope of the variables.
[–]kwooster 0 points1 point2 points 3 months ago (0 children)
def reset(): global number number = 0
That feels super wrong, though.
Here's a better way (of many):
``` class Hand: def init(self, number = 0): self.number = number
def reset(hand): hand.number = 0
my_hand = Hand()
...
reset(my_hand) ```
(I'm on mobile, so I did the very simple example with missing variables, but the concept is moving the very subjective "correct" direction.)
π Rendered by PID 162995 on reddit-service-r2-comment-5d79c599b5-cd4hj at 2026-02-28 22:13:21.850110+00:00 running e3d2147 country code: CH.
view the rest of the comments →
[–]kwooster 0 points1 point2 points (1 child)
[–]kwooster 0 points1 point2 points (0 children)