首页 > 编程语言 > 详细

Python之数学题目练习

时间:2017-06-17 13:40:43      阅读:306      评论:0      收藏:0      [点我收藏+]

 

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

技术分享

他的数学推理:

技术分享

然后下面是我的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))

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

Python之数学题目练习

原文:http://www.cnblogs.com/goodboy-heyang/p/7040010.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!