数据结构(Python语言描述)Kenneth A. Lambert 第一版 习题答案参考1.3

#计算一个弹性小球从一个给定的初试高度落下后做弹跳运动经过的总距离

height = float(input("Enter the height: "))
bounces = int(input("Enter the number of times the ball is allowed to continue bouncing:"))
bounciness = 0.6
distance = 0
for eachPass in range(bounces):
    distance += height
    height *= bounciness
    distance += height
print('\nTotal distance traveled is:',distance,'.')

该题目是第一章第三题,计算一个有弹性的小球从给定高度(程序中设定为输入数据)落下,不断弹跳,计算这一运动过程中的运动距离

你可能感兴趣的:(算法,数据结构)