MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / kinetic_energy

Function kinetic_energy

physics/kinetic_energy.py:21–44  ·  view source on GitHub ↗

Calculate kinetic energy. The kinetic energy of a non-rotating object of mass m traveling at a speed v is ½mv² >>> kinetic_energy(10,10) 500.0 >>> kinetic_energy(0,10) 0.0 >>> kinetic_energy(10,0) 0.0 >>> kinetic_energy(20,-20) 4000.0 >>> kinetic_energy

(mass: float, velocity: float)

Source from the content-addressed store, hash-verified

19
20
21def kinetic_energy(mass: float, velocity: float) -> float:
22 """
23 Calculate kinetic energy.
24
25 The kinetic energy of a non-rotating object of mass m traveling at a speed v is ½mv²
26
27 >>> kinetic_energy(10,10)
28 500.0
29 >>> kinetic_energy(0,10)
30 0.0
31 >>> kinetic_energy(10,0)
32 0.0
33 >>> kinetic_energy(20,-20)
34 4000.0
35 >>> kinetic_energy(0,0)
36 0.0
37 >>> kinetic_energy(2,2)
38 4.0
39 >>> kinetic_energy(100,100)
40 500000.0
41 """
42 if mass < 0:
43 raise ValueError("The mass of a body cannot be negative")
44 return 0.5 * mass * abs(velocity) * abs(velocity)
45
46
47if __name__ == "__main__":

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected