python 斐波那契数列 fibonacci

在python中生成fibonacci数列的函数

def fibonacci():
    list = []
    while 1:
        if(len(list) < 2):
            list.append(1)
        else:
            list.append(list[-1]+list[-2])
        yield list[-1] #1 # change this line so it yields its list instead of 1

our_generator = fibonacci()
my_output = []

for i in range(10):
    my_output = (next(our_generator))
    print(my_output)

 

posted on 2017-05-15 15:45  lion_zheng  阅读(284)  评论(0编辑  收藏  举报

导航