zoukankan      html  css  js  c++  java
  • 实例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)
    
    #解本问题有多种方法,此方法并不是标准答案,读者可以自己尝试各种方法。
    

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

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

  • 相关阅读:
    在禅道中实现WORD等OFFICE文档转换为PDF进行在线浏览
    慎用 supportedRuntime
    定时开关机方案
    谨慎使用Sql server data tool 架构比对排除
    生成数据字典
    Cordova开发速记
    SQLSERVER 2012 收缩日志
    QService 服务容器
    使用用户自定义类型 CLR UDT
    使用DOTNETZIP过滤并压缩相对目录
  • 原文地址:https://www.cnblogs.com/wby-110/p/12584331.html
Copyright © 2011-2022 走看看