From 21a5c9d9c6daf9b3eae8634e73f0c5e3f46486c6 Mon Sep 17 00:00:00 2001 From: Vini Antunes <57882903+ViniViniAntunes@users.noreply.github.com> Date: Sat, 4 Oct 2025 18:50:34 -0300 Subject: [PATCH 01/16] Create magnetic_flux.py Add magnetic_flux.py --- physics/magnetic_flux.py | 87 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 physics/magnetic_flux.py diff --git a/physics/magnetic_flux.py b/physics/magnetic_flux.py new file mode 100644 index 000000000000..b255d848d253 --- /dev/null +++ b/physics/magnetic_flux.py @@ -0,0 +1,87 @@ +""" +Magnetic flux (Φ) is a scalar quantity that measures the number of magnetic field lines (B) +that pass through a closed area (A). Furthermore, the magnetic flux depends on the angle +formed between the magnetic field and the normal line (N) in area A. Check out the formula +used to calculate this flux: + ------------ + | Φ = B.A.cos(θ) | + ------------ + +Φ = magnetic flux (weber (Wb) or tesla square meter (T.m²)) +B = magnetic field (tesla (T)) +A = area (square meter (m²)) +θ = angle between magnetic field and normal line (degrees (°)) + +(Description adapted from https://en.wikipedia.org/wiki/Ideal_gas_law ) +""" + +from math import cos, radians as deg_to_rad + + +def check_args( + magnetic_field: float, + area: float, + angle: float +) -> None: + """ + Check that the arguments are valid + """ + + # Ensure valid instance + if not isinstance(magnetic_field, (int, float)): + raise TypeError("Invalid magnetic field. Should be an integer or float.") + + if not isinstance(area, (int, float)): + raise TypeError("Invalid area. Should be an integer or float.") + + if not isinstance(angle, (int, float)): + raise TypeError("Invalid angle. Should be an integer or float.") + + # Ensure valid angle + if angle < 0 or angle > 180: + raise ValueError("Invalid angle. Range is 0-180 degrees.") + + # Ensure valid magnetic field + if magnetic_field < 0: + raise ValueError("Invalid magnetic field. Should be a positive number.") + + # Ensure valid area + if area < 0: + raise ValueError("Invalid area. Should be a positive number.") + + +def magnetic_flux( + magnetic_field: float, + area: float, + angle: float +) -> float: + """ + >>> magnetic_flux(50.0, 2, 0.0) + 250.0 + >>> magnetic_flux(1.5, 3.0, 60.0) + 2.25 + >>> magnetic_flux(1.5, 3.0, -60.0) + 2.25 + >>> magnetic_flux(0.5, 4.0, 90.0) + 0.0 + >>> magnetic_flux(1, 2.0, 180.0) + -2.0 + >>> magnetic_flux(-1.0, 2.0, 30.0) + Traceback (most recent call last): + ... ValueError: Invalid magnetic field. Should be a positive number. + >>> magnetic_flux(1.0, 'a', 30.0) + Traceback (most recent call last): + ... TypeError: Invalid area. Should be an integer or float. + >>> magnetic_flux(1.0, -2.0, 30.0) + Traceback (most recent call last): + ... ValueError: Invalid area. Should be a positive number. + """ + check_args(magnetic_field, area, angle) + radians = deg_to_rad(angle) + return magnetic_field * area * cos(radians) + + +if __name__ == "__main__": + from doctest import testmod + + testmod() From ccb3e926a2bbb43e88e9b32c28eac404c46ff293 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 4 Oct 2025 22:00:38 +0000 Subject: [PATCH 02/16] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- physics/magnetic_flux.py | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/physics/magnetic_flux.py b/physics/magnetic_flux.py index b255d848d253..538230857f0c 100644 --- a/physics/magnetic_flux.py +++ b/physics/magnetic_flux.py @@ -18,11 +18,7 @@ from math import cos, radians as deg_to_rad -def check_args( - magnetic_field: float, - area: float, - angle: float -) -> None: +def check_args(magnetic_field: float, area: float, angle: float) -> None: """ Check that the arguments are valid """ @@ -36,11 +32,11 @@ def check_args( if not isinstance(angle, (int, float)): raise TypeError("Invalid angle. Should be an integer or float.") - + # Ensure valid angle if angle < 0 or angle > 180: raise ValueError("Invalid angle. Range is 0-180 degrees.") - + # Ensure valid magnetic field if magnetic_field < 0: raise ValueError("Invalid magnetic field. Should be a positive number.") @@ -50,11 +46,7 @@ def check_args( raise ValueError("Invalid area. Should be a positive number.") -def magnetic_flux( - magnetic_field: float, - area: float, - angle: float -) -> float: +def magnetic_flux(magnetic_field: float, area: float, angle: float) -> float: """ >>> magnetic_flux(50.0, 2, 0.0) 250.0 From ce63ace742d45a2366d7118136eb5dd2af3cb2a3 Mon Sep 17 00:00:00 2001 From: Vini Antunes <57882903+ViniViniAntunes@users.noreply.github.com> Date: Sat, 4 Oct 2025 19:11:05 -0300 Subject: [PATCH 03/16] Update magnetic_flux.py Fix the test string mode --- physics/magnetic_flux.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/physics/magnetic_flux.py b/physics/magnetic_flux.py index b255d848d253..83224e93318b 100644 --- a/physics/magnetic_flux.py +++ b/physics/magnetic_flux.py @@ -57,11 +57,9 @@ def magnetic_flux( ) -> float: """ >>> magnetic_flux(50.0, 2, 0.0) - 250.0 - >>> magnetic_flux(1.5, 3.0, 60.0) - 2.25 - >>> magnetic_flux(1.5, 3.0, -60.0) - 2.25 + 100.0 + >>> magnetic_flux(50, 2, 60.0) + 50.0 >>> magnetic_flux(0.5, 4.0, 90.0) 0.0 >>> magnetic_flux(1, 2.0, 180.0) From 78aba635ac8d731962f8993325b1253bfcbc13bb Mon Sep 17 00:00:00 2001 From: Vini Antunes <57882903+ViniViniAntunes@users.noreply.github.com> Date: Sat, 4 Oct 2025 22:33:35 -0300 Subject: [PATCH 04/16] Update magnetic_flux.py Fix test mode string --- physics/magnetic_flux.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/physics/magnetic_flux.py b/physics/magnetic_flux.py index 538230857f0c..fc950b10ee74 100644 --- a/physics/magnetic_flux.py +++ b/physics/magnetic_flux.py @@ -49,11 +49,9 @@ def check_args(magnetic_field: float, area: float, angle: float) -> None: def magnetic_flux(magnetic_field: float, area: float, angle: float) -> float: """ >>> magnetic_flux(50.0, 2, 0.0) - 250.0 + 100.0 >>> magnetic_flux(1.5, 3.0, 60.0) 2.25 - >>> magnetic_flux(1.5, 3.0, -60.0) - 2.25 >>> magnetic_flux(0.5, 4.0, 90.0) 0.0 >>> magnetic_flux(1, 2.0, 180.0) From 68edbdbc4a88593be41da74f2c0e7cb842e0968b Mon Sep 17 00:00:00 2001 From: Vini Antunes <57882903+ViniViniAntunes@users.noreply.github.com> Date: Sat, 4 Oct 2025 22:45:44 -0300 Subject: [PATCH 05/16] Update magnetic_flux.py Fitting to ruff.yml --- physics/magnetic_flux.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/physics/magnetic_flux.py b/physics/magnetic_flux.py index 83224e93318b..87f716e4e641 100644 --- a/physics/magnetic_flux.py +++ b/physics/magnetic_flux.py @@ -1,8 +1,9 @@ """ -Magnetic flux (Φ) is a scalar quantity that measures the number of magnetic field lines (B) -that pass through a closed area (A). Furthermore, the magnetic flux depends on the angle -formed between the magnetic field and the normal line (N) in area A. Check out the formula -used to calculate this flux: +________________________________________________________________________________________ +Magnetic flux (Φ) is a scalar quantity that measures the number of magnetic field +lines (B) that pass through a closed area (A). Furthermore, the magnetic flux depends +on the angle formed between the magnetic field and the normal line (N) in area A. +Check out the formula used to calculate this flux: ------------ | Φ = B.A.cos(θ) | ------------ @@ -15,8 +16,7 @@ (Description adapted from https://en.wikipedia.org/wiki/Ideal_gas_law ) """ -from math import cos, radians as deg_to_rad - +from math import cos, radians def check_args( magnetic_field: float, @@ -75,8 +75,8 @@ def magnetic_flux( ... ValueError: Invalid area. Should be a positive number. """ check_args(magnetic_field, area, angle) - radians = deg_to_rad(angle) - return magnetic_field * area * cos(radians) + rad = radians(angle) + return magnetic_field * area * cos(rad) if __name__ == "__main__": From ce697974d0458c7dbb120620987fee69c3e72569 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 5 Oct 2025 01:51:32 +0000 Subject: [PATCH 06/16] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- physics/magnetic_flux.py | 1 + 1 file changed, 1 insertion(+) diff --git a/physics/magnetic_flux.py b/physics/magnetic_flux.py index 6d6c4d965ead..f152c66ca9ea 100644 --- a/physics/magnetic_flux.py +++ b/physics/magnetic_flux.py @@ -18,6 +18,7 @@ from math import cos, radians + def check_args(magnetic_field: float, area: float, angle: float) -> None: """ Check that the arguments are valid From 0055eba425a21977c220f82cb5a544862993f8a8 Mon Sep 17 00:00:00 2001 From: Vini Antunes <57882903+ViniViniAntunes@users.noreply.github.com> Date: Sat, 4 Oct 2025 22:56:26 -0300 Subject: [PATCH 07/16] Update magnetic_flux.py Round output --- physics/magnetic_flux.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/physics/magnetic_flux.py b/physics/magnetic_flux.py index 6d6c4d965ead..e82012b96a1f 100644 --- a/physics/magnetic_flux.py +++ b/physics/magnetic_flux.py @@ -68,7 +68,7 @@ def magnetic_flux(magnetic_field: float, area: float, angle: float) -> float: """ check_args(magnetic_field, area, angle) rad = radians(angle) - return magnetic_field * area * cos(rad) + return round(magnetic_field * area * cos(rad), 1) if __name__ == "__main__": From ca645a4729d7301f3bc3830f7ac8255127d44046 Mon Sep 17 00:00:00 2001 From: Vini Antunes <57882903+ViniViniAntunes@users.noreply.github.com> Date: Sat, 4 Oct 2025 23:08:32 -0300 Subject: [PATCH 08/16] Update magnetic_flux.py Fixing testmod string --- physics/magnetic_flux.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/physics/magnetic_flux.py b/physics/magnetic_flux.py index e82012b96a1f..af5613fdacef 100644 --- a/physics/magnetic_flux.py +++ b/physics/magnetic_flux.py @@ -58,13 +58,16 @@ def magnetic_flux(magnetic_field: float, area: float, angle: float) -> float: -2.0 >>> magnetic_flux(-1.0, 2.0, 30.0) Traceback (most recent call last): - ... ValueError: Invalid magnetic field. Should be a positive number. + ... + ValueError: Invalid magnetic field. Should be a positive number. >>> magnetic_flux(1.0, 'a', 30.0) Traceback (most recent call last): - ... TypeError: Invalid area. Should be an integer or float. + ... + TypeError: Invalid area. Should be an integer or float. >>> magnetic_flux(1.0, -2.0, 30.0) Traceback (most recent call last): - ... ValueError: Invalid area. Should be a positive number. + ... + ValueError: Invalid area. Should be a positive number. """ check_args(magnetic_field, area, angle) rad = radians(angle) From 89e36b3cadfa702928bd6c5cd998f34fd043fc8f Mon Sep 17 00:00:00 2001 From: Vini Antunes Date: Mon, 6 Oct 2025 11:23:37 -0300 Subject: [PATCH 09/16] Add first_law_of_thermodynamics.py --- physics/first_law_of_thermodynamics.py | 151 +++++++++++++++++++++++++ 1 file changed, 151 insertions(+) create mode 100644 physics/first_law_of_thermodynamics.py diff --git a/physics/first_law_of_thermodynamics.py b/physics/first_law_of_thermodynamics.py new file mode 100644 index 000000000000..1c490de28704 --- /dev/null +++ b/physics/first_law_of_thermodynamics.py @@ -0,0 +1,151 @@ +""" +________________________________________________________________________________________ +The first law of thermodynamics states that, when energy passes into or out of a system +(as work, heat, or matter), the system's internal energy changes in accordance with the +law of conservation of energy. This also results in the observation that, in an +externally isolated system, even with internal changes, the sum of all forms of energy +must remain constant, as energy cannot be created or destroyed. + +Check out the formula used to calculate this flux: + -------------- + | Q = ΔU + W | + -------------- + +Q = heat added or removed from the system. +ΔU = variation of internal energy of the system. +W = work done by the system on its surroundings. + +OBS: All units must be equal to each other. +(Description adapted from https://en.wikipedia.org/wiki/Laws_of_thermodynamics ) +""" + + +def check_args(argument: float) -> None: + """ + Check that the arguments are valid + """ + + # Ensure valid instance + if not isinstance(argument, (int, float)): + raise TypeError("Invalid argument. Should be an integer or float.") + + +def categorize_system(argument_value: float, argument_name: str) -> None: + """ + Categorizes the system based on the work done, heat added/removed, + and internal energy variation. + """ + + if argument_name == "work": + if argument_value == 0: + print("The system is isochoric (constant volume).") + elif argument_value > 0: + print("The system is expanding.") + elif argument_value < 0: + print("The system is compressing.") + + elif argument_name == "heat": + if argument_value == 0: + print("The system is adiabatic (no heat exchange).") + elif argument_value > 0: + print("The system is endothermic (absorbing heat).") + elif argument_value < 0: + print("The system is exothermic (releasing heat).") + + elif argument_name == "internal_energy_variation": + if argument_value == 0: + print("The system is isothermic (constant internal energy)") + elif argument_value > 0: + print("The internal energy of the system is increasing. It heating up.") + elif argument_value < 0: + print("The internal energy of the system is decreasing. It cooling down.") + + +def work(heat: float, internal_energy_variation: float) -> float: + """ + >>> work(50.0, -20.0) + The system is endothermic (absorbing heat). + The internal energy of the system is decreasing. It cooling down. + The system is expanding. + 70.0 + >>> work(50.0, 50.0) + The system is endothermic (absorbing heat). + The internal energy of the system is increasing. It heating up. + The system is isochoric (constant volume). + 0.0 + >>> work(-50.0, 20.0) + The system is exothermic (releasing heat). + The internal energy of the system is increasing. It heating up. + The system is compressing. + -70.0 + """ + check_args(heat) + check_args(internal_energy_variation) + + categorize_system(heat, "heat") + categorize_system(internal_energy_variation, "internal_energy_variation") + + work = heat - internal_energy_variation + categorize_system(work, "work") + return round(work, 1) + +def heat(internal_energy_variation: float, work: float) -> float: + """ + >>> heat(-20.0, 30.0) + The internal energy of the system is decreasing. It cooling down. + The system is expanding. + The system is endothermic (absorbing heat). + 10.0 + >>> heat(50.0, 0.0) + The internal energy of the system is increasing. It heating up. + The system is isochoric (constant volume). + The system is endothermic (absorbing heat). + 50.0 + >>> heat(20.0, -70.0) + The internal energy of the system is increasing. It heating up. + The system is compressing. + The system is exothermic (releasing heat). + -50.0 + """ + check_args(internal_energy_variation) + check_args(work) + + categorize_system(internal_energy_variation, "internal_energy_variation") + categorize_system(work, "work") + + heat = round(internal_energy_variation + work, 1) + categorize_system(heat, "heat") + return heat + +def internal_energy_variation(heat: float, work: float) -> float: + """ + >>> internal_energy_variation(50.0, 30.0) + The system is endothermic (absorbing heat). + The system is expanding. + The internal energy of the system is increasing. It heating up. + 20.0 + >>> internal_energy_variation(50.0, 0.0) + The system is endothermic (absorbing heat). + The system is isochoric (constant volume). + The internal energy of the system is increasing. It heating up. + 50.0 + >>> internal_energy_variation(-50.0, -70.0) + The system is exothermic (releasing heat). + The system is compressing. + The internal energy of the system is increasing. It heating up. + 20.0 + """ + check_args(heat) + check_args(work) + + categorize_system(heat, "heat") + categorize_system(work, "work") + + internal_energy_variation = round(heat - work, 1) + categorize_system(internal_energy_variation, "internal_energy_variation") + return internal_energy_variation + +if __name__ == "__main__": + from doctest import testmod + + testmod() From d53a1d83fc18d0a13c70c8426961ca65ac4aafaf Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 6 Oct 2025 14:32:06 +0000 Subject: [PATCH 10/16] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- physics/first_law_of_thermodynamics.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/physics/first_law_of_thermodynamics.py b/physics/first_law_of_thermodynamics.py index 1c490de28704..cd5dfda4a9cd 100644 --- a/physics/first_law_of_thermodynamics.py +++ b/physics/first_law_of_thermodynamics.py @@ -43,7 +43,7 @@ def categorize_system(argument_value: float, argument_name: str) -> None: print("The system is expanding.") elif argument_value < 0: print("The system is compressing.") - + elif argument_name == "heat": if argument_value == 0: print("The system is adiabatic (no heat exchange).") @@ -51,7 +51,7 @@ def categorize_system(argument_value: float, argument_name: str) -> None: print("The system is endothermic (absorbing heat).") elif argument_value < 0: print("The system is exothermic (releasing heat).") - + elif argument_name == "internal_energy_variation": if argument_value == 0: print("The system is isothermic (constant internal energy)") @@ -84,11 +84,12 @@ def work(heat: float, internal_energy_variation: float) -> float: categorize_system(heat, "heat") categorize_system(internal_energy_variation, "internal_energy_variation") - + work = heat - internal_energy_variation categorize_system(work, "work") return round(work, 1) + def heat(internal_energy_variation: float, work: float) -> float: """ >>> heat(-20.0, 30.0) @@ -112,11 +113,12 @@ def heat(internal_energy_variation: float, work: float) -> float: categorize_system(internal_energy_variation, "internal_energy_variation") categorize_system(work, "work") - + heat = round(internal_energy_variation + work, 1) categorize_system(heat, "heat") return heat + def internal_energy_variation(heat: float, work: float) -> float: """ >>> internal_energy_variation(50.0, 30.0) @@ -140,11 +142,12 @@ def internal_energy_variation(heat: float, work: float) -> float: categorize_system(heat, "heat") categorize_system(work, "work") - + internal_energy_variation = round(heat - work, 1) categorize_system(internal_energy_variation, "internal_energy_variation") return internal_energy_variation + if __name__ == "__main__": from doctest import testmod From 96529481e0a9629cb04ac997b3393f82ec37ade4 Mon Sep 17 00:00:00 2001 From: Vini Antunes Date: Mon, 6 Oct 2025 11:35:17 -0300 Subject: [PATCH 11/16] Fix typo --- physics/first_law_of_thermodynamics.py | 34 +++++++++++++------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/physics/first_law_of_thermodynamics.py b/physics/first_law_of_thermodynamics.py index 1c490de28704..cda04e40f091 100644 --- a/physics/first_law_of_thermodynamics.py +++ b/physics/first_law_of_thermodynamics.py @@ -20,7 +20,7 @@ """ -def check_args(argument: float) -> None: +def __check_args(argument: float) -> None: """ Check that the arguments are valid """ @@ -30,7 +30,7 @@ def check_args(argument: float) -> None: raise TypeError("Invalid argument. Should be an integer or float.") -def categorize_system(argument_value: float, argument_name: str) -> None: +def __categorize_system(argument_value: float, argument_name: str) -> None: """ Categorizes the system based on the work done, heat added/removed, and internal energy variation. @@ -79,14 +79,14 @@ def work(heat: float, internal_energy_variation: float) -> float: The system is compressing. -70.0 """ - check_args(heat) - check_args(internal_energy_variation) + __check_args(heat) + __check_args(internal_energy_variation) - categorize_system(heat, "heat") - categorize_system(internal_energy_variation, "internal_energy_variation") + __categorize_system(heat, "heat") + __categorize_system(internal_energy_variation, "internal_energy_variation") work = heat - internal_energy_variation - categorize_system(work, "work") + __categorize_system(work, "work") return round(work, 1) def heat(internal_energy_variation: float, work: float) -> float: @@ -107,14 +107,14 @@ def heat(internal_energy_variation: float, work: float) -> float: The system is exothermic (releasing heat). -50.0 """ - check_args(internal_energy_variation) - check_args(work) + __check_args(internal_energy_variation) + __check_args(work) - categorize_system(internal_energy_variation, "internal_energy_variation") - categorize_system(work, "work") + __categorize_system(internal_energy_variation, "internal_energy_variation") + __categorize_system(work, "work") heat = round(internal_energy_variation + work, 1) - categorize_system(heat, "heat") + __categorize_system(heat, "heat") return heat def internal_energy_variation(heat: float, work: float) -> float: @@ -135,14 +135,14 @@ def internal_energy_variation(heat: float, work: float) -> float: The internal energy of the system is increasing. It heating up. 20.0 """ - check_args(heat) - check_args(work) + __check_args(heat) + __check_args(work) - categorize_system(heat, "heat") - categorize_system(work, "work") + __categorize_system(heat, "heat") + __categorize_system(work, "work") internal_energy_variation = round(heat - work, 1) - categorize_system(internal_energy_variation, "internal_energy_variation") + __categorize_system(internal_energy_variation, "internal_energy_variation") return internal_energy_variation if __name__ == "__main__": From 507b41c454839abef619b31b02b8a7ea2e08d775 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 6 Oct 2025 14:38:10 +0000 Subject: [PATCH 12/16] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- physics/first_law_of_thermodynamics.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/physics/first_law_of_thermodynamics.py b/physics/first_law_of_thermodynamics.py index bd20f3dc802e..1d8df9215ace 100644 --- a/physics/first_law_of_thermodynamics.py +++ b/physics/first_law_of_thermodynamics.py @@ -84,7 +84,7 @@ def work(heat: float, internal_energy_variation: float) -> float: __categorize_system(heat, "heat") __categorize_system(internal_energy_variation, "internal_energy_variation") - + work = heat - internal_energy_variation __categorize_system(work, "work") return round(work, 1) @@ -113,7 +113,7 @@ def heat(internal_energy_variation: float, work: float) -> float: __categorize_system(internal_energy_variation, "internal_energy_variation") __categorize_system(work, "work") - + heat = round(internal_energy_variation + work, 1) __categorize_system(heat, "heat") return heat @@ -142,7 +142,7 @@ def internal_energy_variation(heat: float, work: float) -> float: __categorize_system(heat, "heat") __categorize_system(work, "work") - + internal_energy_variation = round(heat - work, 1) __categorize_system(internal_energy_variation, "internal_energy_variation") return internal_energy_variation From 2d2935cd8aa5a044a3c2adf2de11f3035b19b827 Mon Sep 17 00:00:00 2001 From: Vini Antunes Date: Mon, 6 Oct 2025 11:48:52 -0300 Subject: [PATCH 13/16] Fix testmod string --- physics/first_law_of_thermodynamics.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/physics/first_law_of_thermodynamics.py b/physics/first_law_of_thermodynamics.py index bd20f3dc802e..adb842f501f3 100644 --- a/physics/first_law_of_thermodynamics.py +++ b/physics/first_law_of_thermodynamics.py @@ -22,7 +22,13 @@ def __check_args(argument: float) -> None: """ - Check that the arguments are valid + Check that the arguments are valid. + >>> __check_args(50.0) + >>> __check_args(-20) + >>> __check_args("50") + Traceback (most recent call last): + ... + TypeError: Invalid argument. Should be an integer or float. """ # Ensure valid instance @@ -34,6 +40,16 @@ def __categorize_system(argument_value: float, argument_name: str) -> None: """ Categorizes the system based on the work done, heat added/removed, and internal energy variation. + >>> __categorize_system(0, "work") + The system is isochoric (constant volume). + >>> __categorize_system(50, "heat") + The system is endothermic (absorbing heat). + >>> __categorize_system(-20, "internal_energy_variation") + The internal energy of the system is decreasing. It cooling down. + >>> __categorize_system(10, "invalid") + Traceback (most recent call last): + ... + ValueError: Invalid argument name. Should be 'work', 'heat', or 'internal_energy_variation'. """ if argument_name == "work": @@ -60,6 +76,10 @@ def __categorize_system(argument_value: float, argument_name: str) -> None: elif argument_value < 0: print("The internal energy of the system is decreasing. It cooling down.") + else: + error_type = "Invalid argument name." + error_msg = "Should be 'work', 'heat', or 'internal_energy_variation'." + raise ValueError(f"{error_type} {error_msg}") def work(heat: float, internal_energy_variation: float) -> float: """ From 56299272ea280812b4fad801353a27e57df4fe45 Mon Sep 17 00:00:00 2001 From: Vini Antunes Date: Mon, 6 Oct 2025 11:50:57 -0300 Subject: [PATCH 14/16] Fix testmod string --- physics/first_law_of_thermodynamics.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/physics/first_law_of_thermodynamics.py b/physics/first_law_of_thermodynamics.py index a1459e60170a..adb842f501f3 100644 --- a/physics/first_law_of_thermodynamics.py +++ b/physics/first_law_of_thermodynamics.py @@ -104,7 +104,7 @@ def work(heat: float, internal_energy_variation: float) -> float: __categorize_system(heat, "heat") __categorize_system(internal_energy_variation, "internal_energy_variation") - + work = heat - internal_energy_variation __categorize_system(work, "work") return round(work, 1) @@ -133,7 +133,7 @@ def heat(internal_energy_variation: float, work: float) -> float: __categorize_system(internal_energy_variation, "internal_energy_variation") __categorize_system(work, "work") - + heat = round(internal_energy_variation + work, 1) __categorize_system(heat, "heat") return heat @@ -162,7 +162,7 @@ def internal_energy_variation(heat: float, work: float) -> float: __categorize_system(heat, "heat") __categorize_system(work, "work") - + internal_energy_variation = round(heat - work, 1) __categorize_system(internal_energy_variation, "internal_energy_variation") return internal_energy_variation From e635166e9eebd7c7f307d5d6a99659fbcfba84c4 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 6 Oct 2025 14:51:54 +0000 Subject: [PATCH 15/16] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- physics/first_law_of_thermodynamics.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/physics/first_law_of_thermodynamics.py b/physics/first_law_of_thermodynamics.py index adb842f501f3..ad809236570d 100644 --- a/physics/first_law_of_thermodynamics.py +++ b/physics/first_law_of_thermodynamics.py @@ -81,6 +81,7 @@ def __categorize_system(argument_value: float, argument_name: str) -> None: error_msg = "Should be 'work', 'heat', or 'internal_energy_variation'." raise ValueError(f"{error_type} {error_msg}") + def work(heat: float, internal_energy_variation: float) -> float: """ >>> work(50.0, -20.0) @@ -104,7 +105,7 @@ def work(heat: float, internal_energy_variation: float) -> float: __categorize_system(heat, "heat") __categorize_system(internal_energy_variation, "internal_energy_variation") - + work = heat - internal_energy_variation __categorize_system(work, "work") return round(work, 1) @@ -133,7 +134,7 @@ def heat(internal_energy_variation: float, work: float) -> float: __categorize_system(internal_energy_variation, "internal_energy_variation") __categorize_system(work, "work") - + heat = round(internal_energy_variation + work, 1) __categorize_system(heat, "heat") return heat @@ -162,7 +163,7 @@ def internal_energy_variation(heat: float, work: float) -> float: __categorize_system(heat, "heat") __categorize_system(work, "work") - + internal_energy_variation = round(heat - work, 1) __categorize_system(internal_energy_variation, "internal_energy_variation") return internal_energy_variation From e84d0bdda7a4849d175336a67849c7c3b423e094 Mon Sep 17 00:00:00 2001 From: Vini Antunes Date: Mon, 6 Oct 2025 12:10:05 -0300 Subject: [PATCH 16/16] Fix testmod string --- physics/first_law_of_thermodynamics.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/physics/first_law_of_thermodynamics.py b/physics/first_law_of_thermodynamics.py index adb842f501f3..da10568cec2b 100644 --- a/physics/first_law_of_thermodynamics.py +++ b/physics/first_law_of_thermodynamics.py @@ -49,7 +49,7 @@ def __categorize_system(argument_value: float, argument_name: str) -> None: >>> __categorize_system(10, "invalid") Traceback (most recent call last): ... - ValueError: Invalid argument name. Should be 'work', 'heat', or 'internal_energy_variation'. + ValueError: Should be 'work', 'heat', or 'internal_energy_variation'. """ if argument_name == "work": @@ -77,9 +77,7 @@ def __categorize_system(argument_value: float, argument_name: str) -> None: print("The internal energy of the system is decreasing. It cooling down.") else: - error_type = "Invalid argument name." - error_msg = "Should be 'work', 'heat', or 'internal_energy_variation'." - raise ValueError(f"{error_type} {error_msg}") + raise ValueError("Should be 'work', 'heat', or 'internal_energy_variation'.") def work(heat: float, internal_energy_variation: float) -> float: """