实例011:养兔子

100个不同类型的python语言趣味编程题

实例011:养兔子

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

此题与趣味算法第五题是同一题,因此在这里列出另一种解法,具体分析请看趣味算法第五题。

程序分析:考虑到三个月成熟,可以构建四个数据,其中:一月兔每个月长大成为二月兔,二月兔变三月兔,三月兔变成年兔,成年兔(包括新成熟的三月兔)生等量的一月兔。

month=int(input('繁殖几个月?: '))
month_1=1
month_2=0
month_3=0
month_elder=0
for i in range(month):
    month_1,month_2,month_3,month_elder = month_elder+month_3,month_1,month_2,month_elder+month_3
    print('第%d个月共'%(i+1),month_1+month_2+month_3+month_elder,'对兔子')
    print('其中1月兔:',month_1)
    print('其中2月兔:',month_2)
    print('其中3月兔:',month_3)
    print('其中成年兔:',month_elder)

#解本问题有多种方法,此方法并不是标准答案,读者可以自己尝试各种方法。

如果你喜欢我的文章,请滑到下方点个推荐再走.

以给我动力哦;转载请注名出处。然后..请多来做客鸭。

原文地址:https://www.cnblogs.com/wby-110/p/12584331.html