青蛙只能跳1步或者2步
当台阶数为1或2时 总方法数为台阶数 返回即可
当台阶数大于2就要使用递归了
使用了斐波那契数 代码如下
def frog(n): if n 2: return n step_1, step_2 1, 2 for i in range(3, n 1): step_1, step_2 step_2, step_1 step_2 return step_2 n int(input( 请输入台阶数: )) print(frog(n))
结果如下
参考至:(12条消息) 青蛙爬台阶问题的三种解法 python_随便记点东西-CSDN博客_python青蛙跳台阶问题https://blog.csdn.net/xiaolewennofollow/article/details/45271145?utm_medium distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-3.no_search_link depth_1-utm_source distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-3.no_search_link



