Python 递归函数:计算爬楼梯方案
def count_steps(n): if n == 1: return 1 elif n == 2: return 2 else: return count_steps(n-1) + count_steps(n-2)
print(count_steps(20)) # 输出结果为:6765
原文地址: https://www.cveoy.top/t/topic/nBF9 著作权归作者所有。请勿转载和采集!
安全问答是一个知识全球问答,包含丰富的问答知识
def count_steps(n): if n == 1: return 1 elif n == 2: return 2 else: return count_steps(n-1) + count_steps(n-2)
print(count_steps(20)) # 输出结果为:6765
原文地址: https://www.cveoy.top/t/topic/nBF9 著作权归作者所有。请勿转载和采集!