Algorithm

Algorithm implementation Fabonacci:

# Fabonacci: 1, 1, 2, 3, 5, 8, 13, 21, 34, 55

def recursion(n):
    if n == 1 or n == 2:
        return 1
    else:
        return recursion(n-1) + recursion(n-2)

def fabonacci(n):
    for i in range(n):
        print(recursion(i+1), end=' ')

fabonacci(7)

Testing output:

D:	estvenvScriptspython.exe D:/test/algorithm.py
1 1 2 3 5 8 13 
Process finished with exit code 0
原文地址:https://www.cnblogs.com/waynewei/p/14923356.html