Calculates the Mass equivalence of the Energy using m = E/c² in SI units kg from Energy in J. energy (float): Mass of body. Usage example: >>> mass_from_energy(124.56) 1.3859169098203872e-15 >>> mass_from_energy(320) 3.560480179371579e-15 >>> mass_from_energy(0
(energy: float)
| 47 | |
| 48 | |
| 49 | def mass_from_energy(energy: float) -> float: |
| 50 | """ |
| 51 | Calculates the Mass equivalence of the Energy using m = E/c² |
| 52 | in SI units kg from Energy in J. |
| 53 | |
| 54 | energy (float): Mass of body. |
| 55 | |
| 56 | Usage example: |
| 57 | >>> mass_from_energy(124.56) |
| 58 | 1.3859169098203872e-15 |
| 59 | >>> mass_from_energy(320) |
| 60 | 3.560480179371579e-15 |
| 61 | >>> mass_from_energy(0) |
| 62 | 0.0 |
| 63 | >>> mass_from_energy(-967.9) |
| 64 | Traceback (most recent call last): |
| 65 | ... |
| 66 | ValueError: Energy can't be negative. |
| 67 | |
| 68 | """ |
| 69 | if energy < 0: |
| 70 | raise ValueError("Energy can't be negative.") |
| 71 | return energy / c**2 |
| 72 | |
| 73 | |
| 74 | if __name__ == "__main__": |
nothing calls this directly
no outgoing calls
no test coverage detected