Python Advanced #7 - Using Python class for Physics problem to determine distance traveled based on velocity and angle

This post is similar to Python Advanced #6 only it uses a Python class to determine the distance traveled based on velocity and angle.

Instead of using individual functions, we create a class to perform the computations.  The object. "distance", becomes an instance of the class, "Dist_comp", with the angle and velocity being sent to the class.  In our example, we have three angles in a list.  We use 100 ft/s for all examples.

The Python coding is shown below:



 The results are shown below (note that 45 degrees gives the maximum distance):



In the coding above, the 100 ft/s was sent as a constant.  This can also be sent as an entry in a Python dictionary.  This would allow for varying of the velocity as well as the angle.  Some of the previous coding is commented out, and the new code has been added.  This is shown below:



The results of this simulation are the same as those given above.

Comments