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)

结果:

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM