# -*- coding:utf-8 -*-#!python3'''下楼问题。从楼上走到楼下共有h个台阶,每一步有两种走法:走1个台阶,走2个台阶,问有多少可走的方案。用递归思想和迭代思想编程''''''分析:问题可以从最后一次是走1步还是两步,反向考虑'''def take_stairs_recursive(n): if n == 1: return 1 elif n == 2: return 2 else: return take_stairs_recursive(n-1)+take_stairs_recursive(n-2)'''其实就是斐波那契数列'''def take_stairs(n): if n == 1: return 1 if n == 2: return 2 a,b = 1,2 result = 0 for i in range(3,n+1): result = a + b a = b b = result return resultprint(take_stairs_recursive(10))print(take_stairs(10))