斐波那契数列

2018-07-04  本文已影响0人  Levi__s

###################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=",")

上一篇下一篇

猜你喜欢

热点阅读