Python-100-Days/Day66-75/code/generator01.py

22 lines
292 B
Python

def fib():
a, b = 0, 1
while True:
a, b = b, a + b
yield a
def even(gen):
for val in gen:
if val % 2 == 0:
yield val
def main():
gen = even(fib())
for _ in range(10):
print(next(gen))
if __name__ == '__main__':
main()