Python中的弹跳球

2024-09-27 07:32:48 发布

您现在位置:Python中文网/ 问答频道 /正文

球从H高度(米)落下,反弹回B*H高度,其中B为反弹系数,0<;B<;1.当球从弹跳系数为B的表面上的高度H跌落时,计算球在静止前所经过的总距离。当高度小于1m时,球不会弹回

Input:  
H=5, B=0.5​
Output:  
12.5  
Explanation :  
5 + 2.5 + 2.5 + 1.25 + 1.25

我试过,

def bouncingBall(h, bounce, window):

           if h != 0 and bounce > 0 and bounce < 1 and window < h:
          
               count = 1
               current = h*bounce
               while current > window:
                 current *= bounce
                 count += 2
               return h + 3 * current
           else:
                return -1

Tags: andlt距离inputoutputreturn高度count

热门问题