Physics

Write the Phyton functions to solve the following physics problems:

  1. Write the function amps(), that from a given electric potential difference value expressed in volts and a given resistance value expressed in ohms of an electric circuit, returns the electric current intensity in accordance to Ohm’s law.

    Save the function into the file named physics1.py. The function must pass the following doctest:

    >>> co = amps(5.0, 7.5)
    >>> round(co, 4)
    0.6667
    >>> co = amps(2, 1.1)
    >>> round(co, 4)
    1.8182
    

    Note

    You can download the file with tests physics1.txt

  2. Write the function velocity() that, given a time in minutes and a distance in kilometers, corresponding to a uniform lineal motion of a body travel, returns its velocity in m/s.

    Save the function into the file named physics2.py. The function must pass the following doctest:

    >>> v1 = velocity(122.95, 42.195) #Marathon
    >>> round(v1, 1)
    5.7
    >>> v2 = velocity(2, 2)
    >>> round(v2, 2)
    16.67
    

    Note

    You can download the file with tests physics2.txt

  3. Write function ualm() that given the acceleration (in \(\mathrm{m/s}^2\)), the starting velocity (in \(\mathrm{m/s}\)), the starting position, in meters, and a time in minutes, corresponding to an uniformly accelerated linear motion of a body travel, returns the final position of this body in meters.

    Save the function into the file named physics3.py. The function must pass the following doctest:

    >>> x = ualm(1, 1, 0, 1)
    >>> round(x, 1)
    1860.0
    >>> h = ualm(-9.80665, 0, 1000, 0.2)
    >>> round(h, 1)
    293.9
    

    Note

    You can download the file with tests physics3.txt

  4. An automobile is at the origin and travels in a uniform linear motion with a velocity v1 expressed in km/h. Another car that is at a distance of x meters forward from the previous one starts to move t seconds after the first car and in the same direction at a constant velocity v2 (in km/h). Write the function car() that given v1, v2, x and t returns the time (in seconds) that the first car needs to catch up with the second one. We will assume that velocity v2 in inferior than v1 and that the first car will catch up with the second one after the second one starts moving.

    Save the function into the file named physics4.py. The function must pass the following doctest:

    >>> t = car(16.66, 10, 5500, 200)
    >>> round(t, 1)
    2672.7
    >>> t = car(20, 15, 9000, 0)
    >>> round(t, 1)
    6480.0
    

    Note

    You can download the file with tests physics4.txt

Solution

A solution of these functions is provided in the physics1.py, physics2.py, physics3.py, physics4.py