Takes the temperature (in K) and molar mass (in kg/mol) of a gas and returns the average speed of a molecule in the gas (in m/s). Examples: >>> avg_speed_of_molecule(273, 0.028) # nitrogen at 273 K 454.3488755062257 >>> avg_speed_of_molecule(300, 0.032) # oxygen at 300 K
(temperature: float, molar_mass: float)
| 52 | |
| 53 | |
| 54 | def avg_speed_of_molecule(temperature: float, molar_mass: float) -> float: |
| 55 | """ |
| 56 | Takes the temperature (in K) and molar mass (in kg/mol) of a gas |
| 57 | and returns the average speed of a molecule in the gas (in m/s). |
| 58 | |
| 59 | Examples: |
| 60 | |
| 61 | >>> avg_speed_of_molecule(273, 0.028) # nitrogen at 273 K |
| 62 | 454.3488755062257 |
| 63 | >>> avg_speed_of_molecule(300, 0.032) # oxygen at 300 K |
| 64 | 445.5257273433045 |
| 65 | >>> avg_speed_of_molecule(-273, 0.028) # invalid temperature |
| 66 | Traceback (most recent call last): |
| 67 | ... |
| 68 | Exception: Absolute temperature cannot be less than 0 K |
| 69 | >>> avg_speed_of_molecule(273, 0) # invalid molar mass |
| 70 | Traceback (most recent call last): |
| 71 | ... |
| 72 | Exception: Molar mass should be greater than 0 kg/mol |
| 73 | """ |
| 74 | |
| 75 | if temperature < 0: |
| 76 | raise Exception("Absolute temperature cannot be less than 0 K") |
| 77 | if molar_mass <= 0: |
| 78 | raise Exception("Molar mass should be greater than 0 kg/mol") |
| 79 | return (8 * R * temperature / (pi * molar_mass)) ** 0.5 |
| 80 | |
| 81 | |
| 82 | def mps_speed_of_molecule(temperature: float, molar_mass: float) -> float: |
nothing calls this directly
no outgoing calls
no test coverage detected