Created
August 5, 2019 09:06
-
-
Save alexboche/459007a9f0687fb9d8a1b2051b73ec39 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def make_averager(): | |
count = 0 | |
total = 0 | |
def averager(new_value): | |
# nonlocal count, total # doesn't work | |
# global count, total | |
count = count + 1 | |
total = total + new_value | |
print(total/count) | |
return total/count | |
return averager | |
averager = make_averager() | |
averager(1) | |
averager(2) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment