Calculates the Energy equivalence of the Mass using E = mc² in SI units J from Mass in kg. mass (float): Mass of body. Usage example: >>> energy_from_mass(124.56) 1.11948945063458e+19 >>> energy_from_mass(320) 2.8760165719578165e+19 >>> energy_from_mass(0)
(mass: float)
| 22 | |
| 23 | |
| 24 | def energy_from_mass(mass: float) -> float: |
| 25 | """ |
| 26 | Calculates the Energy equivalence of the Mass using E = mc² |
| 27 | in SI units J from Mass in kg. |
| 28 | |
| 29 | mass (float): Mass of body. |
| 30 | |
| 31 | Usage example: |
| 32 | >>> energy_from_mass(124.56) |
| 33 | 1.11948945063458e+19 |
| 34 | >>> energy_from_mass(320) |
| 35 | 2.8760165719578165e+19 |
| 36 | >>> energy_from_mass(0) |
| 37 | 0.0 |
| 38 | >>> energy_from_mass(-967.9) |
| 39 | Traceback (most recent call last): |
| 40 | ... |
| 41 | ValueError: Mass can't be negative. |
| 42 | |
| 43 | """ |
| 44 | if mass < 0: |
| 45 | raise ValueError("Mass can't be negative.") |
| 46 | return mass * c**2 |
| 47 | |
| 48 | |
| 49 | def mass_from_energy(energy: float) -> float: |
nothing calls this directly
no outgoing calls
no test coverage detected