美文网首页
斐波那契数列

斐波那契数列

作者: Levi__s | 来源:发表于2018-07-04 21:33 被阅读0次

    ###################1

    # def fibonacci03(count):

    #    if count == 1:

    #        return 1

    #    if count == 2:

    #        return 2

    #    return fibonacci03(count -1) + fibonacci03(count -2)

    # if __name__ == '__main__':

    # a=fibonacci(5)

    # print(a)

    #################2

    # ls = []

    # def fibonacci(count):

    #    index = 0

    #    first,second = 1,2

    #    while index <= count:

    #        ls.append(first)

    #        first,second = second,first + second

    #        index +=1

    #

    # if __name__ == '__main__':

    #

    #    fibonacci(10)

    # for i in ls:

    #    print(i,end=",")

    #################3

    def fibonacci(count):

    index =0

        first, second =1,2

        while index < count:

    yield first

    first,second = second,first + second

    index +=1

    if __name__ =='__main__':

    res = fibonacci(10)

    # print(next(res))

        for iin res:

    print(i,end=",")

    相关文章

      网友评论

          本文标题:斐波那契数列

          本文链接:https://www.haomeiwen.com/subject/skbyuftx.html