Python尾递归-求斐波那契数列

# coding=utf-8
# Fibonacci.py

Fib = {}
def Fibonacci(n):
    global Fib
    if Fib.has_key(n): return Fib[n]
    if n == 0: return 1
    if n == 1: return 1
    Fib[n] = Fibonacci(n-1) + Fibonacci(n-2)
    return Fib[n]

if __name__ == '__main__':
    for i in range(50):
        print Fibonacci(i)
posted @ 2015-01-27 12:45  Mx.Hu  阅读(304)  评论(0编辑  收藏  举报