zoukankan      html  css  js  c++  java
  • Python之数学题目练习

    首先,下面的题目来自我的大学同学的分享,他用数学证明,我用编程计算机发现了答案。

    他的数学推理:

    然后下面是我的Python代码:

    #coding=utf-8
    
    # 井的高度
    well_hegith = 12
    
    print ('井的高度是%ld'%(well_hegith))
    
    # 白天
    def daytime(allHeight):
        allHeight = allHeight + 5
        if allHeight>well_hegith:
            allHeight = -1
        else:
            allHeight = allHeight * 0.8
        return allHeight
    
    
    # 黑夜
    def night(allHeight):
        allHeight = allHeight + 3
        if allHeight>well_hegith:
            allHeight = -1
        else:
            allHeight = allHeight*2.0/3.0
        return allHeight
    
    
    # 白天开始算,是不是白天,默认开始是白天
    isDayTime = True
    # 总的高度,默认开始是0
    allHeight = 0
    # 天数
    days = 0.0
    
    while allHeight >= 0:
        print days
        days = days + 0.5
        if isDayTime:
            allHeight = daytime(allHeight)
            isDayTime = False
        else:
            allHeight = night(allHeight)
            isDayTime = True
        print ('高度:=======%lf'%(allHeight))

     我的程序最后跑出来进入了无限循环中。。。

  • 相关阅读:
    HTML5元素标记释义
    Mvc使用Partial View 来封装上传控件
    订单页过滤,sql写法
    防止提交重复订单的方法
    查询数据库所有列
    asp.net 异常处理
    7. DateTime,TimeSpan
    8.1.thread
    8.2.Task
    2.2. Array
  • 原文地址:https://www.cnblogs.com/goodboy-heyang/p/7040010.html
Copyright © 2011-2022 走看看