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)
| 19 | |
| 20 | |
| 21 | def 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 | |
| 47 | if __name__ == "__main__": |
nothing calls this directly
no outgoing calls
no test coverage detected