成免费的crm,久久国产精品新农夫导航新妓网,恋夜秀场全部视频安卓手机,女校花强奷在线播放A级

Python 練習實例20

python 練習實例20

python 編程100例python 編程100例

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

程序分析:無

程序源代碼:

python 實例:

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

以上實例輸出結果為:

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

python 編程100例python 編程100例

下一節:python 練習實例21

python 編程100例

相關文章