From 2ab3bf2689d21e7375539c79ecee358e9d7c3359 Mon Sep 17 00:00:00 2001 From: robertjcalistri <85811008+robertjcalistri@users.noreply.github.com> Date: Mon, 14 Aug 2023 05:31:53 -0400 Subject: [PATCH] =?UTF-8?q?Added=20functions=20to=20calculate=20temperatur?= =?UTF-8?q?e=20of=20an=20ideal=20gas=20and=20number=20o=E2=80=A6=20(#8919)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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 * Update physics/ideal_gas_law.py Updated formatting Co-authored-by: Tianyi Zheng * Update physics/ideal_gas_law.py Removed unnecessary parentheses Co-authored-by: Tianyi Zheng * Update physics/ideal_gas_law.py Removed unnecessary parentheses Co-authored-by: Tianyi Zheng * 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 --- physics/ideal_gas_law.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/physics/ideal_gas_law.py b/physics/ideal_gas_law.py index 805da47b0..09b4fb3a9 100644 --- a/physics/ideal_gas_law.py +++ b/physics/ideal_gas_law.py @@ -53,6 +53,40 @@ def volume_of_gas_system(moles: float, kelvin: float, pressure: float) -> float: 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 moles_of_gas_system(kelvin: float, volume: float, pressure: float) -> float: + """ + >>> moles_of_gas_system(100, 5, 10) + 0.06013618199229246 + >>> moles_of_gas_system(110, 5009, 1000) + 5476.766101807144 + >>> moles_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