somepeople

斐波那契数列

def fib(n):
    a = 0
    b = 1
    num = 0
    while num < n:
        yield(b)
        a,b = b,a+ b
        num += 1
fib = fib(20)
print(list(fib))
#[1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765]

 

posted on 2020-07-19 12:41  Hello_Thanos  阅读(86)  评论(0编辑  收藏  举报

导航