这个函数应该计算d的答案,我遇到的问题是我需要使用1到10的值作为t。我很确定我会为此使用范围函数,但我不完全确定如何让函数取1到10的数字。下面是我到目前为止的代码:
g = 9.8
def fallingDistance(t):
d = .5 * g * pow(t, 2)
return round(d, 2)
t =
d = fallingDistance(t)
for i in range (10):
print("The falling distance = ", d)
for t in range(10):
print("The falling distance in %d seconds is %s" %(t, fallingDistance(t)))
输出:The falling distance in 0 seconds is 0.0
The falling distance in 1 seconds is 4.9
The falling distance in 2 seconds is 19.6
The falling distance in 3 seconds is 44.1
The falling distance in 4 seconds is 78.4
The falling distance in 5 seconds is 122.5
The falling distance in 6 seconds is 176.4
The falling distance in 7 seconds is 240.1
The falling distance in 8 seconds is 313.6
The falling distance in 9 seconds is 396.9