mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-02-25 10:28:39 +00:00
Added functions to calculate temperature of an ideal gas and number of moles of an ideal gas
This commit is contained in:
parent
ce218c57f1
commit
e4faf6bfb5
@ -52,6 +52,37 @@ def volume_of_gas_system(moles: float, kelvin: float, pressure: float) -> float:
|
||||
raise ValueError("Invalid inputs. Enter positive value.")
|
||||
return moles * kelvin * UNIVERSAL_GAS_CONSTANT / pressure
|
||||
|
||||
def temperature_of_gas_system(moles: float, volume: float, pressure: float) -> float:
|
||||
"""
|
||||
>>> temperature_of_gas_system(2, 100, 5)
|
||||
30.068090996146232
|
||||
>>> temperature_of_gas_system(11,5009,1000)
|
||||
54767.66101807144
|
||||
>>> temperature_of_gas_system(3, -0.46, 23.5)
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValueError: Invalid inputs. Enter positive value.
|
||||
"""
|
||||
if moles < 0 or volume < 0 or pressure < 0:
|
||||
raise ValueError("Invalid inputs. Enter positive value.")
|
||||
|
||||
return (pressure * volume) / (moles * UNIVERSAL_GAS_CONSTANT)
|
||||
|
||||
def num_moles_of_gas_in_system(kelvin: float, volume: float, pressure: float) -> float:
|
||||
"""
|
||||
>>> temperature_of_gas_system(100, 5, 10)
|
||||
0.06013618199229246
|
||||
>>> temperature_of_gas_system(110,5009,1000)
|
||||
5476.766101807144
|
||||
>>> temperature_of_gas_system(3, -0.46, 23.5)
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValueError: Invalid inputs. Enter positive value.
|
||||
"""
|
||||
if kelvin < 0 or volume < 0 or pressure < 0:
|
||||
raise ValueError("Invalid inputs. Enter positive value.")
|
||||
|
||||
return (pressure * volume) / (kelvin * UNIVERSAL_GAS_CONSTANT)
|
||||
|
||||
if __name__ == "__main__":
|
||||
from doctest import testmod
|
||||
|
Loading…
x
Reference in New Issue
Block a user