69pao国产精品视频-久久精品一区二区二三区-精品国产精品亚洲一本大道-99国产综合一区久久

Python 練習實例20

python 練習實例20

python 編程100例python 編程100例

題目:一球從100米高度自由落下,每次落地后反跳回原高度的一半;再落下,求它在第10次落地時,共經(jīng)過多少米?第10次反彈多高?

程序分析:無

程序源代碼:

python 實例:

#!/usr/bin/python
# -*- coding: utf-8 -*-
 
tour = []
height = []
 
hei = 100.0 # 起始高度
tim = 10 # 次數(shù)
 
for i in range(1, tim + 1):
    # 從第二次開始,落地時的距離應(yīng)該是反彈高度乘以2(彈到最高點再落下)
    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]))

以上實例輸出結(jié)果為:

總高度:tour = 299.609375
第10次反彈高度:height = 0.09765625

python 編程100例python 編程100例

下一節(jié):python 練習實例21

python 編程100例

相關(guān)文章