5.4 Making Our Own Module
117
DESCRIPTION
Module for computing vertical motion
characteristics for a projectile.
FUNCTIONS
max_height(v0)
Compute maximum height reached, given the initial vertical
velocity v0. Assume negligible air resistance.
time_of_flight(v0)
Compute time in the air, given the initial vertical
velocity v0. Assume negligible air resistance.
y(v0, t)
Compute vertical position at time t, given the initial vertical
velocity v0. Assume negligible air resistance.
We recognize the doc strings in the printout and should realize that it is a good idea
to keep those doc strings informative.
With the following interactive session, comparing the answers to hand calculations (using the formulas and a calculator), we confirm that the module now seems
to work as intended,
In [1]: import vertical_motion as vm
In [2]: vm.y(v0=5, t=0.6)
Out[2]: 1.2342
In [3]: vm.time_of_flight(v0=5)
Out[3]: 1.019367991845056
In [4]: vm.max_height(v0=5)
Out[4]: 1.27420998980632
We now have a useful version of our own vertical motion module, from which
imports work just like from built-in modules. Still, there is room for useful
modifications, as we will turn to next.
117
DESCRIPTION
Module for computing vertical motion
characteristics for a projectile.
FUNCTIONS
max_height(v0)
Compute maximum height reached, given the initial vertical
velocity v0. Assume negligible air resistance.
time_of_flight(v0)
Compute time in the air, given the initial vertical
velocity v0. Assume negligible air resistance.
y(v0, t)
Compute vertical position at time t, given the initial vertical
velocity v0. Assume negligible air resistance.
We recognize the doc strings in the printout and should realize that it is a good idea
to keep those doc strings informative.
With the following interactive session, comparing the answers to hand calculations (using the formulas and a calculator), we confirm that the module now seems
to work as intended,
In [1]: import vertical_motion as vm
In [2]: vm.y(v0=5, t=0.6)
Out[2]: 1.2342
In [3]: vm.time_of_flight(v0=5)
Out[3]: 1.019367991845056
In [4]: vm.max_height(v0=5)
Out[4]: 1.27420998980632
We now have a useful version of our own vertical motion module, from which
imports work just like from built-in modules. Still, there is room for useful
modifications, as we will turn to next.
