1 tour = [] 2 height = [] 3 4 hei = 100.0 5 tim = 10 6 7 for i in range(1,tim+1): 8 if i == 1: 9 tour.append(hei) 10 else: 11 tour.append(hei*2) 12 hei /= 2 13 height.append(hei) 14 15 print(‘总高度:tour = {0}‘.format(sum(tour))) 16 print(‘第10次反弹高度:height = {0}‘.format(height[-1]))
#结果:
高度:tour = 299.609375
第10次反弹高度:height = 0.0976562
原文:https://www.cnblogs.com/monsterhy123/p/12565951.html