Skip to content

Instantly share code, notes, and snippets.

@panzi
Forked from skatenerd/gotcha.py
Last active August 29, 2015 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save panzi/150ef9eeeca20cce2871 to your computer and use it in GitHub Desktop.
Save panzi/150ef9eeeca20cce2871 to your computer and use it in GitHub Desktop.
def make_adder():
grand_total = 0
def adder(to_add):
nonlocal grand_total
print("Grand total moved from: %s" % grand_total)
grand_total += to_add
print("To: %s \n" % grand_total)
return grand_total
return adder
adder = make_adder()
adder(1)
adder(2)
adder(3)
@panzi
Copy link
Author

panzi commented Jan 4, 2015

And now it works. So where is the problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment