python经典面试题(斐波那契)

斐波那契数列,又称黄金分割数列,从第三项开始,每一项都等于前两项之和

F0 = 0  

F1 = 1

F2 = Fn-1 + Fn-2

请写一个函数find_mth_fibo(n) 在斐波那契数列里返回第N个数值 如find_mth_fibo(3) 则返回数值2 find_mth_fibo(10)则返回 55

def find_mth_fibo(n):
    if n == 1:
        return 1
    elif n == 2:
        return 1
    elif n > 2:
        return find_mth_fibo(n - 1) + find_mth_fibo(n - 2)

if __name__ == '__main__':
    print(find_mth_fibo(10))

你可能感兴趣的:(python,python经典面试题,python后端开发笔试题,爬虫笔试题)