Created
April 9, 2019 06:15
-
-
Save cocodrips/72da9d604fce88cbd43f13fcd5bce3b6 to your computer and use it in GitHub Desktop.
Pythonのasyncio
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 averager(): | |
total = 0 | |
count = 0 | |
average = 0 | |
while True: | |
term = yield average | |
total += term | |
count += 1 | |
average = total / count | |
# avg = averager() | |
# next(avg) | |
# Out[20]: 0 | |
# avg.send(3) | |
# Out[21]: 3.0 | |
# avg.send(6) | |
# Out[22]: 4.5 | |
# avg.send(10) | |
# Out[23]: 6.333333333333333 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment