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

Function rms_speed_of_molecule

physics/rms_speed_of_molecule.py:26–38  ·  view source on GitHub ↗

>>> rms_speed_of_molecule(100, 2) 35.315279554323226 >>> rms_speed_of_molecule(273, 12) 23.821458421977443

(temperature: float, molar_mass: float)

Source from the content-addressed store, hash-verified

24
25
26def rms_speed_of_molecule(temperature: float, molar_mass: float) -> float:
27 """
28 >>> rms_speed_of_molecule(100, 2)
29 35.315279554323226
30 >>> rms_speed_of_molecule(273, 12)
31 23.821458421977443
32 """
33 if temperature < 0:
34 raise Exception("Temperature cannot be less than 0 K")
35 if molar_mass <= 0:
36 raise Exception("Molar mass cannot be less than or equal to 0 kg/mol")
37 else:
38 return (3 * UNIVERSAL_GAS_CONSTANT * temperature / molar_mass) ** 0.5
39
40
41if __name__ == "__main__":

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected