Skip to content

Commit a9c2586

Browse files
committed
committed from zkp
1 parent b875f03 commit a9c2586

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

协程/average.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
def average():
2+
total = 0.0
3+
count = 0
4+
pivot = 0
5+
while True:
6+
total += yield pivot
7+
count += 1
8+
pivot = total / count
9+
10+
if __name__ == '__main__':
11+
t = average()
12+
next(t)
13+
print(t.send(10))
14+
print(t.send(20))
15+
print(t.send(30))

0 commit comments

Comments
 (0)