Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this assignment you will write some Python statements within this Jupyter Notebook that are answers to the posed programming questions. By saving what you

"In this assignment you will write some Python statements within this Jupyter Notebook that are answers to the posed programming questions. By saving what you have written into the notebook, and submitting the resulting IPython file via conneX, the teaching team will be able to evaluate your work. ", " ", "You are encouraged to create your own notebooks in order to experiment with programming ideas. Once you have solutions that you wish to submit, they can be copy-and-pasted into this notebook. You should, however, always ensure your Python statements do work by evaluating them within this notebook. ", " ", "** This notebook describes Part A. Part B is in another notebook. **" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Part A: A little bit of physics ", " ", "Calculating the distance travelled by a moving object is a common task in physics. For example, if an object is already moving at some initial speed (or **initial velocity**), and then **accelerates** over an interval of **time**, we can calculate the distance travelled by the object as: ", " ", "$$\\textit{d} = V_i \\times t + \\frac{1}{2} \\times a \\times t^2$$ ", " ", "That is, $V_i$ is the initial velocity in meters per second ($m/s$), $t$ is time in seconds ($s$), and acceleration $a$ is in meters-per-second squared ($m/s^2$). ", " ", " ", "The code cell below already contains Python statements for prompting the user for input, calling a finished function (which does not yet exist), and printing the returned result. ", " ", "You must write a function named ```dist_with_accel``` within the code cell below." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# The following is known as a 'docstring', and in a later lecture ", "# we will explore how it is normally best used to document a ", "# Python function. ", " ", "''' ", "function: dist_with_accel ", " ", "This function calculates the distance travelled by some object ", "that has a (possibly non-zero, possibly negative) initial velocity ", "subject to a (possibly negative, possibly zero, but definitely ", "constant) acceleration over a positive interval of time. ", " ", "Input parameters ", "---------------- ", " ", "* initial_velocity: speed at which the object is moving ", " at time 0 (in meters-per-second). ", " ", "* acceleration: rate of change of speed of the moving ", " object (in meters-per-second squared). ", " ", "* time: number of seconds over which the object is moving ", " ", " ", "Result value ", "------------ ", " ", "* The distance travelled by the moving object given the ", " initial velocity, acceleration, and time. ", " ", " ", "Output ", "------ ", " ", "* The function produces no output to the console or to any files. ", " ", "''' ", " ", "# ", "# WRITE THE dist_with_accel FUNCTION IMMEDIATELY BELOW. ", "# ", " ", " ", " ", " ", " ", "# DO NOT MODIFY ANYTHING FROM HERE TO THE BOTTOM OF THIS CODE CELL!! ", " ", "# The following main() function prompts the user for required ", "# input, calls the completed function, and then outputs ", "# the result. ", "# ", "# Some sample values and expected results: ", "# 9.5, 7.2, 3.14 --> 65.32456 ", "# 100, -3, 5.6 --> 512.96 ", "# 0, 9.8, 100 --> 49000.0 ", " ", "def main(): ", " vi = float(input(\"What is the initial velocity (m/s)? \")) ", " a = float(input(\"What is rate of acceleration (m/s^2)? \")) ", " t = float(input(\"How many seconds of travel to calculate (s)? \")) ", " ", " d = dist_with_accel(vi, a, t) ", " ", " print(\"The distance is: \", d) ", " ", "main() "

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions