def accumulator(): total = 0 while True: value = yield total total += value acc = accumulator() next(acc) # 启动 print(acc.send(10)) # 10 print(acc.send(20)) # 30
练习:答案