即使现实总是不尽人意,也永远无法阻碍我们变得优秀。

python3 兔子繁殖问题

题目 有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第三个月后每个月又生一对兔子,假如兔子都不死,问每个月的兔子总数为多少?

代码:

month = int(input("繁殖几个月?:"))
month_1 = 1
month_2 = 0
month_3 = 0
month_adult = 0
for i in range(month):
    month_1, month_2, month_3, month_adult = month_adult + month_3, month_1, month_2, month_adult+month_3
    print("第{}个月共{} 对兔子".format(i+1, month_1+month_2+month_3+month_adult))
    print("其中1月兔:", month_1)
    print("其中2月兔:", month_2)
    print("其中3月兔:", month_3)
    print("其中成年兔:", month_adult)

结果:

 

posted @ 2019-05-27 14:52  依概率收敛于你  阅读(3828)  评论(0编辑  收藏  举报