Physics¶
Write the Phyton functions to solve the following physics problems:
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.txtWrite 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.txtWrite 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.txtAn automobile is at the origin and travels in a uniform linear motion with a velocity
v1expressed in km/h. Another car that is at a distance ofxmeters forward from the previous one starts to movetseconds after the first car and in the same direction at a constant velocityv2(in km/h). Write the functioncar()that givenv1,v2,xandtreturns the time (in seconds) that the first car needs to catch up with the second one. We will assume that velocityv2in inferior thanv1and 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