Falling Distance
The following formula can be used to determine the distance an object falls due to gravity in a specific time period, starting from rest:
The variables in the formula are as follows: d is the distance in meters, g is 9.8, and t is the amount of time in seconds, that the object has been falling.
Write a function named falling_distance that accepts an object’s falling time in seconds as an argument. The function should return the distance in meters that the object has fallen
during that time interval. Write a program that calls the function in a loop that passes the values 1 through 10 as arguments and displays the return value.
Falling Distance Python Code:
#The function named falling_distance that accepts
#an object’s falling time in seconds as an argument.
#The function should return the distance in meters
#that the object has fallen during that time interval.
def falling_distance(time):
gravity = 9.8
distance = 0.5 * gravity * (time ** 2)
return distance
# Calls the function in a loop that passes the
#values 1 through 10 as arguments and displays
#the return value
for time in range(1, 11):
distance = falling_distance(time)
print("Time:", time, "seconds | Distance:", distance, "meters")
Executed Output:
Time: 1 seconds | Distance: 4.9 meters
Time: 2 seconds | Distance: 19.6 meters
Time: 3 seconds | Distance: 44.1 meters
Time: 4 seconds | Distance: 78.4 meters
Time: 5 seconds | Distance: 122.50000000000001 meters
Time: 6 seconds | Distance: 176.4 meters
Time: 7 seconds | Distance: 240.10000000000002 meters
Time: 8 seconds | Distance: 313.6 meters
Time: 9 seconds | Distance: 396.90000000000003 meters
Time: 10 seconds | Distance: 490.00000000000006 meters