Fibonacci 的Python实现

Fibonacci 的Python实现

def fib(max):
    L = [1,1]
    i = 0
    j = 0
    if max == 0:
        return 
    elif max == 1:
        return [1]
    elif max == 2:
        return L
    else:
        while i + 2 < max:
            j = L[i] + L[i+1]
            L.append(j)
            i = i + 1
        return L
def fib(max):
    a, b, i = 0, 1, 0
    while i < max:
        print(b)
        a, b = b, a + b
        i = i + 1

转载于:https://www.cnblogs.com/Tristan-Adams/p/9962946.html

你可能感兴趣的:(Fibonacci 的Python实现)