1.百度到的讲解的比较详细的地址,思路写的也比较容易理解:
https://www.cnblogs.com/sangern/p/17404508.html
规律图如下:

total_distance = 100 #首次下落距离就是100
for bottom_count in range(1, 11): #第1次到第10次
rebound = 100*0.5**bottom_count
if bottom_count >= 2:
total_distance += 2*100*0.5**(bottom_count-1)
bottom_count += 1
print(f'球在经过10次落地时,共经过{total_distance}米,第10次反弹{rebound}米')
2.咨询组内同事写的,思路基本和百度到的那篇一样:
total_distance=100
print(f"第10次反弹高度为{100*0.5**10}米") #100*0.5**i(i是第几次)
for i in range(2,11):
total_distance+=100*0.5**(i-1)*2 #距离是100*0.5的(n-1)次方*2
print(f"第10次反弹经过距离为:{total_distance}")
3.老师写的,另一种思路:
tour = [] # 每次落地经过的容器高度
height = [] # 每一次反单的高度
hei = 100.0
for i in range(1, 11):
if i == 1:
tour.append(100)
else:
tour.append(hei * 2)
hei /= 2 # 反单的高度
height.append(hei)
print(tour)
print(sum(tour)) # 计算和
重点还是需求分析,必要是画图,多看几次球落地的规律
4.另一个同事写的:
n = 1#次数
a = 100#经过米数
g = float(100 /2)#反弹的高度
while True:
n=n+1
a=a+g+g
g=float(g/2)
if n==10:
print(f"经过米数{a}")
print(f"反弹的高度{g}")
break
文章介绍了四种不同的编程方法来解决篮球落地后反弹的问题,包括反弹高度和总经过距离的计算。每种方法都基于相同的物理规律,即每次反弹高度减半,但实现方式各有特点,有的使用循环,有的采用递归。最后强调了需求分析和理解规律的重要性。
519

被折叠的 条评论
为什么被折叠?



