high=100n=10high_all=0#第n次落地時走過的長度high_each=0#每次落地的高度defball_lands(n):globalhigh_all,high_each,high#小球第一次落地時ifn==0:high_each=highhigh_all+=high_each#print('1',high_each,high_all)returnhigh_each#從小球第n次落地往前推high_each=high*(1/2)**nprint(u'第%d次小球彈起的高度為:%.2f'%(n,high_each))high_all+=high_each*2#print('2',high_each,high_all)ball_lands(n-1)ball_lands(n)print(u'小球落地%d次,共經(jīng)過%.2f米。'%(n,high_all))
網(wǎng)站導航
- zblogPHP模板zbpkf
- zblog免費模板zblogfree
- zblog模板學習zblogxuexi
- zblogPHP仿站zbpfang