Takes the temperature (in K) and molar mass (in kg/mol) of a gas and returns the most probable speed of a molecule in the gas (in m/s). Examples: >>> mps_speed_of_molecule(273, 0.028) # nitrogen at 273 K 402.65620702280023 >>> mps_speed_of_molecule(300, 0.032) # oxygen at
(temperature: float, molar_mass: float)
| 80 | |
| 81 | |
| 82 | def mps_speed_of_molecule(temperature: float, molar_mass: float) -> float: |
| 83 | """ |
| 84 | Takes the temperature (in K) and molar mass (in kg/mol) of a gas |
| 85 | and returns the most probable speed of a molecule in the gas (in m/s). |
| 86 | |
| 87 | Examples: |
| 88 | |
| 89 | >>> mps_speed_of_molecule(273, 0.028) # nitrogen at 273 K |
| 90 | 402.65620702280023 |
| 91 | >>> mps_speed_of_molecule(300, 0.032) # oxygen at 300 K |
| 92 | 394.8368955535605 |
| 93 | >>> mps_speed_of_molecule(-273, 0.028) # invalid temperature |
| 94 | Traceback (most recent call last): |
| 95 | ... |
| 96 | Exception: Absolute temperature cannot be less than 0 K |
| 97 | >>> mps_speed_of_molecule(273, 0) # invalid molar mass |
| 98 | Traceback (most recent call last): |
| 99 | ... |
| 100 | Exception: Molar mass should be greater than 0 kg/mol |
| 101 | """ |
| 102 | |
| 103 | if temperature < 0: |
| 104 | raise Exception("Absolute temperature cannot be less than 0 K") |
| 105 | if molar_mass <= 0: |
| 106 | raise Exception("Molar mass should be greater than 0 kg/mol") |
| 107 | return (2 * R * temperature / molar_mass) ** 0.5 |
| 108 | |
| 109 | |
| 110 | if __name__ == "__main__": |
nothing calls this directly
no outgoing calls
no test coverage detected