"""计算累计的平均值"""
"""含有装饰器的生成器函数"""
def warpper(func):
def inner(*args,**kwargs):
""""执行装饰器之前的操作"""
g=func(*args,**kwargs)
g.__next__()
"""执行装饰器之后的操作"""
return g
return inner
@warpper
def avgare():
count=0
sum=0
avg=0
num=0
while True:
num=yield num
sum+=num
count+=1
avg=sum/count
print(avg)
g=avgare()
ret=g.send(10)
ret=g.send(20)
ret=g.send(20)
ret=g.send(20)