首页 > 编程语言 > 详细

python3练习100题——020

时间:2018-06-07 12:54:13      阅读:187      评论:0      收藏:0      [点我收藏+]

原题链接:http://www.runoob.com/python/python-exercise-example20.html

题目:一球从100米高度自由落下,每次落地后反跳回原高度的一半;再落下,求它在第10次落地时,共经过多少米?第10次反弹多高?

我的代码:

def ball():
    times=int(input("Hou many times the ball hit the floor?"))
    h=100.0
    record=[]      
    length=100
    for i in range(0,times):
        h=h/2
        record.append(h)
    for i in record[:-1]:
        length += i*2
    print(length)
    print(record[-1])

if __name__ == __main__:
    ball()

思考:

题目本身很容易,但是要搞清楚循环多少次。10次落地时,总路径长度计算的是100+9次来回的路径长度。

python3练习100题——020

原文:https://www.cnblogs.com/drifter/p/9149562.html

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