Skip to content

Commit 2ab3bf2

Browse files
robertjcalistripre-commit-ci[bot]tianyizheng02
authored
Added functions to calculate temperature of an ideal gas and number o… (TheAlgorithms#8919)
* Added functions to calculate temperature of an ideal gas and number of moles of an ideal gas * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update physics/ideal_gas_law.py Renamed function name Co-authored-by: Tianyi Zheng <[email protected]> * Update physics/ideal_gas_law.py Updated formatting Co-authored-by: Tianyi Zheng <[email protected]> * Update physics/ideal_gas_law.py Removed unnecessary parentheses Co-authored-by: Tianyi Zheng <[email protected]> * Update physics/ideal_gas_law.py Removed unnecessary parentheses Co-authored-by: Tianyi Zheng <[email protected]> * Update ideal_gas_law.py Updated incorrect function calls moles of gas system doctests * Update physics/ideal_gas_law.py --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Tianyi Zheng <[email protected]>
1 parent ac68dc1 commit 2ab3bf2

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

physics/ideal_gas_law.py

+34
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,40 @@ def volume_of_gas_system(moles: float, kelvin: float, pressure: float) -> float:
5353
return moles * kelvin * UNIVERSAL_GAS_CONSTANT / pressure
5454

5555

56+
def temperature_of_gas_system(moles: float, volume: float, pressure: float) -> float:
57+
"""
58+
>>> temperature_of_gas_system(2, 100, 5)
59+
30.068090996146232
60+
>>> temperature_of_gas_system(11, 5009, 1000)
61+
54767.66101807144
62+
>>> temperature_of_gas_system(3, -0.46, 23.5)
63+
Traceback (most recent call last):
64+
...
65+
ValueError: Invalid inputs. Enter positive value.
66+
"""
67+
if moles < 0 or volume < 0 or pressure < 0:
68+
raise ValueError("Invalid inputs. Enter positive value.")
69+
70+
return pressure * volume / (moles * UNIVERSAL_GAS_CONSTANT)
71+
72+
73+
def moles_of_gas_system(kelvin: float, volume: float, pressure: float) -> float:
74+
"""
75+
>>> moles_of_gas_system(100, 5, 10)
76+
0.06013618199229246
77+
>>> moles_of_gas_system(110, 5009, 1000)
78+
5476.766101807144
79+
>>> moles_of_gas_system(3, -0.46, 23.5)
80+
Traceback (most recent call last):
81+
...
82+
ValueError: Invalid inputs. Enter positive value.
83+
"""
84+
if kelvin < 0 or volume < 0 or pressure < 0:
85+
raise ValueError("Invalid inputs. Enter positive value.")
86+
87+
return pressure * volume / (kelvin * UNIVERSAL_GAS_CONSTANT)
88+
89+
5690
if __name__ == "__main__":
5791
from doctest import testmod
5892

0 commit comments

Comments
 (0)