python 小球掉落问题

题目:小球从100米高落下,每次会跳原高度的一半,再落下。求它在第10次落地时,经过多少米,反弹多高

代码:

# -*- coding:utf-8 -*-

tour = []
height = []
hei = 100.0 # 起始高度
tim = 10 # 次数

for i in range(1,tim+1):
    if i == 1:
        tour.append(hei)
    else:
        tour.append(2*hei)
    hei /= 2
    height.append(hei)

print('总高度: tour = {0}'.format(sum(tour)))
print('第10次反弹高度:height = {0}'.format(height[-1]))

输出

总高度: tour = 299.609375
第10次反弹高度:height = 0.09765625