标签:
# -*- coding:cp936 -*- def rabbit(n): """ 题目:古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子, 小兔子长到第三个月后每个月又生一对兔子,假如兔子都不死,问每个月的兔子总数为多少? 程序分析:兔子的规律为数列1,1,2,3,5,8,13,21.... """ sum = 0 if n < 3: sum = 1 else: sum = rabbit(n-1) + rabbit(n-2) return sum if (__name__ == ‘__main__‘): month = int(raw_input("输入月份:")) print rabbit(month)
标签:
原文地址:http://www.cnblogs.com/foreverlzj/p/4758801.html