#移动平均值:类似打靶每打一枪看平均环数 def average(): sum = 0 count = 0 avg = 0 while 1: num = yield avg sum+=num count+=1 avg=sum/count g = average() g.__next__() q=g.send(20) q=g.send(15) print(q)
#移动平均值:类似打靶每打一枪看平均环数 def average(): sum = 0 count = 0 avg = 0 while 1: num = yield avg sum+=num count+=1 avg=sum/count g = average() g.__next__() q=g.send(20) q=g.send(15) print(q)