我有两个变量的“恢复系数”(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)
我的结果是,我的结果是8.44米。但是,我有正确的反弹次数(13)。在
为什么我的答案会产生错误的代码?在
在指定
th
时,似乎没有考虑球的上下移动。球下降8米,那么cor意味着球会上升5.6米,也会下降5.6米。改变你的th+=h*2,这就更接近你书中的答案了。在相关问题 更多 >
编程相关推荐