Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
oorrja
GitHub Repository: oorrja/learntosolveit
Path: blob/master/languages/python/design_generator.py
1240 views
1
def mygen():
2
"""Yield 5 until something else is passed back via send()"""
3
a = 5
4
while True:
5
f = yield(a) #yield a and possibly get f in return
6
if f is not None: a = f #store the new value
7
8
g = mygen()
9
print(next(g))
10
print(next(g))
11
g.send(7)
12
print(next(g))
13
14