gpt4 book ai didi

python - 恢复系数

转载 作者:行者123 更新时间:2023-11-30 22:15:32 25 4
gpt4 key购买 nike

我有两个变量中的“恢复系数”( cor )和“初始高度(以米为单位)”( h )。我试图找到“行进的米数”( th ),即 cor * h + cor * h + .... 相同的乘法,直到米数小于 0.10 米。我所做的如下:

cor = float(input("Enter coefficient of restitution : "))
h = float(input("Enter initial height in meters : "))
nob = 0
th = h
while (h >= 0.10):
nob += 1
h *= cor
th += h
print("Meters traveled : {0:.2f}".format(th))
print("Number of bounces : ", nob)

对于 cor = 0.7 和 h = 8,我发现结果是 26.49 米,而我的书上说是 44.82 米。然而,我确实有正确的退回次数(13)。

为什么我的代码会产生错误的答案?

最佳答案

当您指定th时,您似乎没有考虑到球的向下和向上移动。球下降 8m,那么 cor 意味着球会上升 5.6m,也会下降 5.6m。改变你的 th += h*2 ,这会更接近你书上的答案。

cor = float(input("Enter coefficient of restitution : "))
h = float(input("Enter initial height in meters : "))
nob = 0
th = h
while (h >= 0.10):
nob += 1
h *= cor
th += h*2
print("Meters traveled : {0:.2f}".format(th))
print("Number of bounces : ", nob)

关于python - 恢复系数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50276940/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com