JiangLe

python 例程的一个好例子

 

用例程来写一个求平均值的算法

#!/usr/local/python/bin/python3

def FunCore():
    total=0
    counter=0
    average=None
    tmp=yield average
    while True:
        total=total+tmp
        counter=counter+1
        average=total/counter
        tmp=yield average

if __name__ =="__main__":
    fc=FunCore()
    next(fc)
    for x in range(10):
        average=fc.send(x)
        print(average)

 

分类:

技术点:

相关文章:

  • 2021-08-12
  • 2021-12-26
  • 2021-12-09
  • 2021-10-16
  • 2022-02-04
  • 2021-12-05
  • 2021-09-11
  • 2021-09-29
猜你喜欢
  • 2021-12-03
  • 2021-11-21
  • 2021-09-08
  • 2021-10-19
  • 2021-10-01
  • 2021-12-10
  • 2021-09-17
相关资源
相似解决方案