Generating a number sequence in Feibolaqi generator solution python

Because the law Feibolaqi series (1,1,2,3,5 ...) began to show the third number, it is necessary to store the incoming two variables

##计算斐波拉契数列
def fibla():
    yield 1
    yield 1
    f1, f2 = 1, 1
    while True:
        f1, f2 = f2, f1+f2
        yield f2
gen_fib = fibla()
for i in range(20):
    print(next(gen_fib))

The results of the code execution

Alt

Guess you like

Origin blog.csdn.net/zKUN_bit/article/details/93521659