draft of coroutine examples

This commit is contained in:
Luciano Ramalho
2015-02-17 10:07:07 -02:00
parent dfb3c3b895
commit e910ec5458
13 changed files with 326 additions and 25 deletions

View File

@@ -45,7 +45,7 @@ Result = collections.namedtuple('Result', 'sum terms average')
def adder_coro(initial=0):
total = initial
num_terms = 0
count = 0
while True:
try:
term = yield total
@@ -54,8 +54,8 @@ def adder_coro(initial=0):
if term is None:
break
total += term
num_terms += 1
return Result(total, num_terms, total/num_terms)
count += 1
return Result(total, count, total/count)
def prompt():