In: Computer Science
PYTHON
Falling Distance
When an object is falling because of gravity, the following formula can be used to determine the distance the object falls in a specific time period:
d = ½ gt2
The variables in the formula are as follows:
d is the distance in meters
g is 9.8 (the gravitational constant)
t is the amount of time in seconds the object has been falling
Your program will calculate the distance in meters based on the object’s falling distance.
Modularity: Your program should contain 2 functions:
main – will call the falling_distance function in a loop, passing it the values 1 – 10 as arguments (seconds the object has been falling). It will display the returned distance.
falling_distance – will be passed one parameter which is the time in seconds the object has been falling and will calculate and return the distance in meters. falling_distance should be stored in a separate file (module) called distance.py You will import distance before your main function in your original program file.
Input Validation: None needed
Output: Should look like this:
Time Falling Distance
-----------------------------
1 4.90
2 19.60
3 44.10
4 78.40
5 122.50
6 176.40
7 240.10
8 313.60
9 396.90
10 490.00
distance.py:
def falling_distance(i):
return 0.5*9.8*i*i
main.py:
from distance import *
def main():
print("Time Falling Distance")#print on console
print("----------------------------")
for i in range(1,11):
r=falling_distance(i)#call function and print the result
print(i," ",end="")
print("{:.2f}".format(r))
main()#call main function
Screenshots:
Screenshots:
The screenshots are attached below for reference.
Please follow them for output and proper indentation.
Please upvote my answer. Thank you.