SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Tony Gaddis
Chapter:
Value Returning Functions And Modules
Exercise:
Programming Exercises
Question:4 | ISBN:9780132576376 | Edition: 2

Question

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: 

d=1/2gt^{2}

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.

TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Answer

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

 

0 0

Discussions

Post the discussion to improve the above solution.