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

high=[]
tour=[]
hei=100

for i in range(0,10):
    if i == 0:
        tour.append(hei)
    else:
        tour.append(2*hei)
    hei /= 2
    high.append(hei)

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

第一次下落只会经历一次100m,之后由于反弹会导致路程翻倍

你可能感兴趣的:(python,python,开发语言,后端)