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

Function mass_from_energy

physics/mass_energy_equivalence.py:49–71  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

47
48
49def 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
74if __name__ == "__main__":

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected