使用两种方式进行计算

 

def fib(n):
    if n==0:
        return 0
    elif n==1:
        return 1
    else:
        return fib(n-1)+fib(n-2)


def fib2(n):
    a=0
    b=1
    for x in range(n):
        a=a+b
        b=a-b
    return a


if __name__ == "__main__":
    for x in range(10):
        print(x,fib(x),fib2(x))