From e4faf6bfb5e0304b99f8a371d871a1f9b1c44303 Mon Sep 17 00:00:00 2001 From: robertjcalistri Date: Wed, 2 Aug 2023 19:10:07 -0400 Subject: [PATCH 1/8] Added functions to calculate temperature of an ideal gas and number of moles of an ideal gas --- physics/ideal_gas_law.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/physics/ideal_gas_law.py b/physics/ideal_gas_law.py index 805da47b0079..b9544d370a61 100644 --- a/physics/ideal_gas_law.py +++ b/physics/ideal_gas_law.py @@ -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 From 9f684576bb3a66fb9fafed0ce921e5bd4395decb Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 2 Aug 2023 23:12:57 +0000 Subject: [PATCH 2/8] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- physics/ideal_gas_law.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/physics/ideal_gas_law.py b/physics/ideal_gas_law.py index b9544d370a61..f1fa3638ae69 100644 --- a/physics/ideal_gas_law.py +++ b/physics/ideal_gas_law.py @@ -52,6 +52,7 @@ 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) @@ -65,9 +66,10 @@ def temperature_of_gas_system(moles: float, volume: float, pressure: float) -> f """ 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) @@ -81,9 +83,10 @@ def num_moles_of_gas_in_system(kelvin: float, volume: float, pressure: float) -> """ 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 From 2beb2071ce970b80f83bb140dc4f34757d9db7f1 Mon Sep 17 00:00:00 2001 From: robertjcalistri <85811008+robertjcalistri@users.noreply.github.com> Date: Thu, 3 Aug 2023 08:11:16 -0400 Subject: [PATCH 3/8] Update physics/ideal_gas_law.py Renamed function name Co-authored-by: Tianyi Zheng --- physics/ideal_gas_law.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/physics/ideal_gas_law.py b/physics/ideal_gas_law.py index f1fa3638ae69..873c78ef899d 100644 --- a/physics/ideal_gas_law.py +++ b/physics/ideal_gas_law.py @@ -70,7 +70,7 @@ def temperature_of_gas_system(moles: float, volume: float, pressure: float) -> f return (pressure * volume) / (moles * UNIVERSAL_GAS_CONSTANT) -def num_moles_of_gas_in_system(kelvin: float, volume: float, pressure: float) -> float: +def moles_of_gas_system(kelvin: float, volume: float, pressure: float) -> float: """ >>> temperature_of_gas_system(100, 5, 10) 0.06013618199229246 From a2d6d5b574693965a8b0d15e3f1816c11bd317b8 Mon Sep 17 00:00:00 2001 From: robertjcalistri <85811008+robertjcalistri@users.noreply.github.com> Date: Thu, 3 Aug 2023 08:12:55 -0400 Subject: [PATCH 4/8] Update physics/ideal_gas_law.py Updated formatting Co-authored-by: Tianyi Zheng --- physics/ideal_gas_law.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/physics/ideal_gas_law.py b/physics/ideal_gas_law.py index 873c78ef899d..148b19d5a537 100644 --- a/physics/ideal_gas_law.py +++ b/physics/ideal_gas_law.py @@ -57,7 +57,7 @@ def temperature_of_gas_system(moles: float, volume: float, pressure: float) -> f """ >>> temperature_of_gas_system(2, 100, 5) 30.068090996146232 - >>> temperature_of_gas_system(11,5009,1000) + >>> temperature_of_gas_system(11, 5009, 1000) 54767.66101807144 >>> temperature_of_gas_system(3, -0.46, 23.5) Traceback (most recent call last): From c8c29e9611c45c85c7e9c36ea959eea822d3f468 Mon Sep 17 00:00:00 2001 From: robertjcalistri <85811008+robertjcalistri@users.noreply.github.com> Date: Thu, 3 Aug 2023 08:13:13 -0400 Subject: [PATCH 5/8] Update physics/ideal_gas_law.py Removed unnecessary parentheses Co-authored-by: Tianyi Zheng --- physics/ideal_gas_law.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/physics/ideal_gas_law.py b/physics/ideal_gas_law.py index 148b19d5a537..dce2d3d35362 100644 --- a/physics/ideal_gas_law.py +++ b/physics/ideal_gas_law.py @@ -84,7 +84,7 @@ def moles_of_gas_system(kelvin: float, volume: float, pressure: float) -> float: if kelvin < 0 or volume < 0 or pressure < 0: raise ValueError("Invalid inputs. Enter positive value.") - return (pressure * volume) / (kelvin * UNIVERSAL_GAS_CONSTANT) + return pressure * volume / (kelvin * UNIVERSAL_GAS_CONSTANT) if __name__ == "__main__": From b637591ae9be070c9fba215c6b92f0df3f9fdd71 Mon Sep 17 00:00:00 2001 From: robertjcalistri <85811008+robertjcalistri@users.noreply.github.com> Date: Thu, 3 Aug 2023 08:13:29 -0400 Subject: [PATCH 6/8] Update physics/ideal_gas_law.py Removed unnecessary parentheses Co-authored-by: Tianyi Zheng --- physics/ideal_gas_law.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/physics/ideal_gas_law.py b/physics/ideal_gas_law.py index dce2d3d35362..5680cf47ed64 100644 --- a/physics/ideal_gas_law.py +++ b/physics/ideal_gas_law.py @@ -67,7 +67,7 @@ def temperature_of_gas_system(moles: float, volume: float, pressure: float) -> f if moles < 0 or volume < 0 or pressure < 0: raise ValueError("Invalid inputs. Enter positive value.") - return (pressure * volume) / (moles * UNIVERSAL_GAS_CONSTANT) + return pressure * volume / (moles * UNIVERSAL_GAS_CONSTANT) def moles_of_gas_system(kelvin: float, volume: float, pressure: float) -> float: From 5ce54f21805afea7add57a1541016a13b264bda8 Mon Sep 17 00:00:00 2001 From: robertjcalistri <85811008+robertjcalistri@users.noreply.github.com> Date: Thu, 3 Aug 2023 08:15:55 -0400 Subject: [PATCH 7/8] Update ideal_gas_law.py Updated incorrect function calls moles of gas system doctests --- physics/ideal_gas_law.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/physics/ideal_gas_law.py b/physics/ideal_gas_law.py index 5680cf47ed64..670da23db698 100644 --- a/physics/ideal_gas_law.py +++ b/physics/ideal_gas_law.py @@ -72,11 +72,11 @@ def temperature_of_gas_system(moles: float, volume: float, pressure: float) -> f def moles_of_gas_system(kelvin: float, volume: float, pressure: float) -> float: """ - >>> temperature_of_gas_system(100, 5, 10) + >>> moles_of_gas_system(100, 5, 10) 0.06013618199229246 - >>> temperature_of_gas_system(110,5009,1000) + >>> moles_of_gas_system(110,5009,1000) 5476.766101807144 - >>> temperature_of_gas_system(3, -0.46, 23.5) + >>> moles_of_gas_system(3, -0.46, 23.5) Traceback (most recent call last): ... ValueError: Invalid inputs. Enter positive value. From 9ec6e76c549170f45aad8f58d9ac8dba1d672bc3 Mon Sep 17 00:00:00 2001 From: Tianyi Zheng Date: Mon, 14 Aug 2023 02:27:58 -0700 Subject: [PATCH 8/8] Update physics/ideal_gas_law.py --- physics/ideal_gas_law.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/physics/ideal_gas_law.py b/physics/ideal_gas_law.py index 670da23db698..09b4fb3a9c14 100644 --- a/physics/ideal_gas_law.py +++ b/physics/ideal_gas_law.py @@ -74,7 +74,7 @@ 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) + >>> moles_of_gas_system(110, 5009, 1000) 5476.766101807144 >>> moles_of_gas_system(3, -0.46, 23.5) Traceback (most recent call last):