ans = num_rushes(100, 15, 7)
print(ans)
应该返回 19 但我的返回 12?
这是我所拥有的:
def num_rushes(slope_height, rush_height_gain, back_sliding):
rushes = 0
current_height = 0
rush_height_counter = 0
back_sliding_counter = 0
rush_height_gain = 0.95 ** rush_height_counter * rush_height_gain
back_sliding = 0.95 ** back_sliding_counter * back_sliding
while current_height < slope_height:
current_height = current_height + rush_height_gain
rushes += 1
rush_height_counter += 1
back_sliding_counter += 1
if current_height < slope_height:
current_height = current_height - back_sliding
else:
return rushes