题解 | #统计每个月兔子的总数#
统计每个月兔子的总数
https://www.nowcoder.com/practice/1221ec77125d4370833fd3ad5ba72395
#用到了递归函数,其中要注意全局变量的定义 def accrue(month, n, num1): global i for i in range(month + 2, n + 1): num1 = num1 +1 num1 = accrue(i, n, num1) return num1 while True: try: n = int(input()) num = accrue(1, n, 1) print(num) except: break