【发布时间】:2020-05-14 02:41:27
【问题描述】:
height=int(input("Enter the height from which the ball is dropped: "))
count=0
travel_dist=0
index=0.6
if height<=0:
print("The ball cannot bounce...")
else:
while (height>0):
travel_dist=height+(height*index)
count+=1
height=height*index
if height<=0:
break;
print("The ball has bounced ", count, "and travelled the total distance of ", travel_dist)
我尝试移除 while 循环,但无法获得球的整个轨迹。
【问题讨论】:
-
将正值重复乘以 0.6 不会使其为零或负(数学上)。由于舍入错误,如果您等待足够长的时间,它可能会变为零。
-
我投票结束这个问题,因为这显然是一个数学问题,而不是编程问题。
标签: python loops while-loop execution