chemhelper.ideal_gas
chemhelper.ideal_gas ¶
Ideal gas law, PV = nRT.
ideal_gas ¶
ideal_gas(solve_for, substance=None, P=None, V=None, n=None, T=None, m=None, decimals=2, Tunits='K', Vunits='L', Punits='atm')
Solve PV = nRT for one variable.
Give every variable except solve_for. Instead of n you may give the
mass m together with substance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
solve_for
|
(P, V, n, T)
|
The variable to solve for. |
'P'
|
substance
|
str
|
Chemical formula of the gas; needed only with |
None
|
P
|
float
|
Pressure, in |
None
|
V
|
float
|
Volume, in |
None
|
n
|
float
|
Amount of gas in moles. |
None
|
T
|
float
|
Temperature, in |
None
|
m
|
float
|
Mass of gas in grams (used to compute |
None
|
decimals
|
int
|
Decimal places in the result. |
2
|
Tunits
|
(K, C)
|
Units of the given |
'K'
|
Vunits
|
(L, mL)
|
Units of the given |
'L'
|
Punits
|
(atm, torr, mmHg, kPa)
|
Units of the given |
'atm'
|
Returns:
| Type | Description |
|---|---|
float
|
The solved value, in atm (P), L (V), mol (n) or K (T). |
Raises:
| Type | Description |
|---|---|
ValueError
|
For an invalid |
Examples:
>>> ideal_gas('V', n=1, T=273.15, P=1)
22.43
>>> ideal_gas('P', substance='O2', m=32, V=500, Vunits='mL', T=25, Tunits='C')
48.96
Source code in src/chemhelper/ideal_gas.py
ideal_gas_steps ¶
ideal_gas_steps(solve_for, substance=None, P=None, V=None, n=None, T=None, m=None, decimals=2, Tunits='K', Vunits='L', Punits='atm')
Print a step-by-step ideal gas law solution.
Takes the same arguments as :func:ideal_gas.
Examples:
>>> ideal_gas_steps('V', n=1, T=273.15, P=1)
PV = nRT
V = nRT/P
V = 1 moles x 0.0821 L*atm/(mol*K) x 273.15 K / 1 atm = 22.43 L