斐波那契练习

"""

斐波那契数列:从第 3 项开始,每一项都等于前两项之和。

    1, 1, 2, 3, 5, 8, 13, 21..

定义函数,根据长度获取斐波那契数列。

"""
def get_array(long):

    if long == 1:

        return [1]

    elif long == 2:

        return [1, 1]

    else:

        # an = res[n-3]+res[n-2]

        # an = res[-2]+res[-1]

        res = [1, 1]

        while len(res) < long:

            res.append(res[-2] + res[-1])

        return res

res_list = get_array(20)

print(res_list)