From 551ed4c03eb8ef849c4967d3d0e70689c78a47d7 Mon Sep 17 00:00:00 2001 From: Akank Pattnaik <96375225+Sonu-3@users.noreply.github.com> Date: Tue, 7 Oct 2025 20:02:30 +0530 Subject: [PATCH 01/11] Added Hooke's Law --- physics/Hookes_law.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 physics/Hookes_law.py diff --git a/physics/Hookes_law.py b/physics/Hookes_law.py new file mode 100644 index 000000000000..8646c2823d7f --- /dev/null +++ b/physics/Hookes_law.py @@ -0,0 +1,38 @@ +#Hookes Law +""" +Hookes Law states that the Force is directly proportional to the extension or compression of an elastic object, provided the limit of proportionality is not exceeded. + +Formulae : F = -k*x + +F: Force +k: Spring constant +x: displacement from the equilibrium position + +The negative sign indicates that the restoring force acts in the opposite direction to the displacement, always working to bring the object back to its original state. + +Reference: https://en.wikipedia.org/wiki/Hooke%27s_law + +""" + +def hookes_law(k:float, x:float) ->float: + return round(-k*x, 2) + """ + Calculate the Hookes law from the given values of spring constant 'k' + and the displacement 'x' from the equilibrium position. + + >>> hookes_law(200, 0.05) + -10.0 + >>> hookes_law(50, 5) + -250 + >>> hookes_law(300, 3) + -900 + """ + + +if __name__ == "__main__": + import doctest + + doctest.testmod() + + + From 1a0f3538b13b4cf8c82527ef41041b2d471d39a2 Mon Sep 17 00:00:00 2001 From: Akank Pattnaik <96375225+Sonu-3@users.noreply.github.com> Date: Tue, 7 Oct 2025 20:05:39 +0530 Subject: [PATCH 02/11] Rename Hookes_law.py to hookes_law.py --- physics/{Hookes_law.py => hookes_law.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename physics/{Hookes_law.py => hookes_law.py} (100%) diff --git a/physics/Hookes_law.py b/physics/hookes_law.py similarity index 100% rename from physics/Hookes_law.py rename to physics/hookes_law.py From c105f86c3056d0bdfb8687f3b4c4f147916664a3 Mon Sep 17 00:00:00 2001 From: Akank Pattnaik <96375225+Sonu-3@users.noreply.github.com> Date: Tue, 7 Oct 2025 20:11:24 +0530 Subject: [PATCH 03/11] Update hookes_law.py --- physics/hookes_law.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/physics/hookes_law.py b/physics/hookes_law.py index 8646c2823d7f..7bf50ad17fa6 100644 --- a/physics/hookes_law.py +++ b/physics/hookes_law.py @@ -15,7 +15,6 @@ """ def hookes_law(k:float, x:float) ->float: - return round(-k*x, 2) """ Calculate the Hookes law from the given values of spring constant 'k' and the displacement 'x' from the equilibrium position. @@ -27,6 +26,7 @@ def hookes_law(k:float, x:float) ->float: >>> hookes_law(300, 3) -900 """ + return round(-k*x, 2) if __name__ == "__main__": From 44868eaff35985c01e87f62946ae3b59368914c1 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 7 Oct 2025 14:44:09 +0000 Subject: [PATCH 04/11] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- physics/hookes_law.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/physics/hookes_law.py b/physics/hookes_law.py index 7bf50ad17fa6..a878315ecec8 100644 --- a/physics/hookes_law.py +++ b/physics/hookes_law.py @@ -1,4 +1,4 @@ -#Hookes Law +# Hookes Law """ Hookes Law states that the Force is directly proportional to the extension or compression of an elastic object, provided the limit of proportionality is not exceeded. @@ -14,7 +14,8 @@ """ -def hookes_law(k:float, x:float) ->float: + +def hookes_law(k: float, x: float) -> float: """ Calculate the Hookes law from the given values of spring constant 'k' and the displacement 'x' from the equilibrium position. @@ -26,13 +27,10 @@ def hookes_law(k:float, x:float) ->float: >>> hookes_law(300, 3) -900 """ - return round(-k*x, 2) + return round(-k * x, 2) -if __name__ == "__main__": +if __name__ == "__main__": import doctest - - doctest.testmod() - - + doctest.testmod() From 5aa7774680049cc590a48d2184d0a8b1dad6d6a2 Mon Sep 17 00:00:00 2001 From: Akank Pattnaik <96375225+Sonu-3@users.noreply.github.com> Date: Tue, 7 Oct 2025 20:20:02 +0530 Subject: [PATCH 05/11] Update hookes_law.py --- physics/hookes_law.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/physics/hookes_law.py b/physics/hookes_law.py index a878315ecec8..5c7a746ee533 100644 --- a/physics/hookes_law.py +++ b/physics/hookes_law.py @@ -1,6 +1,8 @@ # Hookes Law """ -Hookes Law states that the Force is directly proportional to the extension or compression of an elastic object, provided the limit of proportionality is not exceeded. +Hookes Law states that the Force is directly proportional to the extension +or compression of an elastic object, provided the limit of proportionality +is not exceeded. Formulae : F = -k*x @@ -8,7 +10,9 @@ k: Spring constant x: displacement from the equilibrium position -The negative sign indicates that the restoring force acts in the opposite direction to the displacement, always working to bring the object back to its original state. +The negative sign indicates that the restoring force acts in the opposite +direction to the displacement, always working to bring the object back to +its original state. Reference: https://en.wikipedia.org/wiki/Hooke%27s_law From 060452956318ec9517867d4872e303fa00453fc5 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 7 Oct 2025 14:50:22 +0000 Subject: [PATCH 06/11] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- physics/hookes_law.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/physics/hookes_law.py b/physics/hookes_law.py index 5c7a746ee533..47b1c3bb25cb 100644 --- a/physics/hookes_law.py +++ b/physics/hookes_law.py @@ -1,7 +1,7 @@ # Hookes Law """ -Hookes Law states that the Force is directly proportional to the extension -or compression of an elastic object, provided the limit of proportionality +Hookes Law states that the Force is directly proportional to the extension +or compression of an elastic object, provided the limit of proportionality is not exceeded. Formulae : F = -k*x @@ -10,8 +10,8 @@ k: Spring constant x: displacement from the equilibrium position -The negative sign indicates that the restoring force acts in the opposite -direction to the displacement, always working to bring the object back to +The negative sign indicates that the restoring force acts in the opposite +direction to the displacement, always working to bring the object back to its original state. Reference: https://en.wikipedia.org/wiki/Hooke%27s_law From edf8f34a8f3a3488a1342ed05eb3b6912d5d5ca0 Mon Sep 17 00:00:00 2001 From: Akank Pattnaik <96375225+Sonu-3@users.noreply.github.com> Date: Tue, 7 Oct 2025 20:22:01 +0530 Subject: [PATCH 07/11] Update hookes_law.py --- physics/hookes_law.py | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/physics/hookes_law.py b/physics/hookes_law.py index 47b1c3bb25cb..90713c0753ed 100644 --- a/physics/hookes_law.py +++ b/physics/hookes_law.py @@ -3,27 +3,19 @@ Hookes Law states that the Force is directly proportional to the extension or compression of an elastic object, provided the limit of proportionality is not exceeded. - Formulae : F = -k*x - F: Force k: Spring constant x: displacement from the equilibrium position - The negative sign indicates that the restoring force acts in the opposite direction to the displacement, always working to bring the object back to its original state. - Reference: https://en.wikipedia.org/wiki/Hooke%27s_law - """ - - def hookes_law(k: float, x: float) -> float: """ Calculate the Hookes law from the given values of spring constant 'k' and the displacement 'x' from the equilibrium position. - >>> hookes_law(200, 0.05) -10.0 >>> hookes_law(50, 5) @@ -32,8 +24,6 @@ def hookes_law(k: float, x: float) -> float: -900 """ return round(-k * x, 2) - - if __name__ == "__main__": import doctest From 074967b93eae2af9abe37e9349bd8eb020ea8f23 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 7 Oct 2025 14:52:21 +0000 Subject: [PATCH 08/11] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- physics/hookes_law.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/physics/hookes_law.py b/physics/hookes_law.py index 90713c0753ed..b872650962b9 100644 --- a/physics/hookes_law.py +++ b/physics/hookes_law.py @@ -12,6 +12,8 @@ its original state. Reference: https://en.wikipedia.org/wiki/Hooke%27s_law """ + + def hookes_law(k: float, x: float) -> float: """ Calculate the Hookes law from the given values of spring constant 'k' @@ -24,6 +26,8 @@ def hookes_law(k: float, x: float) -> float: -900 """ return round(-k * x, 2) + + if __name__ == "__main__": import doctest From 723cc86978bb7b7111bc1a8a82934ce375758dc4 Mon Sep 17 00:00:00 2001 From: Akank Pattnaik <96375225+Sonu-3@users.noreply.github.com> Date: Tue, 7 Oct 2025 20:43:26 +0530 Subject: [PATCH 09/11] Update hookes_law.py --- physics/hookes_law.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/physics/hookes_law.py b/physics/hookes_law.py index b872650962b9..7b0fbc16b561 100644 --- a/physics/hookes_law.py +++ b/physics/hookes_law.py @@ -5,8 +5,9 @@ is not exceeded. Formulae : F = -k*x F: Force -k: Spring constant -x: displacement from the equilibrium position +k: spring constant +x: displacement +x is the displacement from the equilibrium position The negative sign indicates that the restoring force acts in the opposite direction to the displacement, always working to bring the object back to its original state. @@ -14,7 +15,7 @@ """ -def hookes_law(k: float, x: float) -> float: +def hookes_law(spring_contant: float, displacement: float) -> float: """ Calculate the Hookes law from the given values of spring constant 'k' and the displacement 'x' from the equilibrium position. From 77382d17407b753c5e423e92e9d9158149e70251 Mon Sep 17 00:00:00 2001 From: Akank Pattnaik <96375225+Sonu-3@users.noreply.github.com> Date: Tue, 7 Oct 2025 20:45:54 +0530 Subject: [PATCH 10/11] Update hookes_law.py --- physics/hookes_law.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/physics/hookes_law.py b/physics/hookes_law.py index 7b0fbc16b561..d3d688d52298 100644 --- a/physics/hookes_law.py +++ b/physics/hookes_law.py @@ -26,7 +26,7 @@ def hookes_law(spring_contant: float, displacement: float) -> float: >>> hookes_law(300, 3) -900 """ - return round(-k * x, 2) + return round(-spring_constant * displacement, 2) if __name__ == "__main__": From 03b9e72a7b73fcaba653d1bd0b59a92dfc030e51 Mon Sep 17 00:00:00 2001 From: Akank Pattnaik <96375225+Sonu-3@users.noreply.github.com> Date: Tue, 7 Oct 2025 20:47:58 +0530 Subject: [PATCH 11/11] Update hookes_law.py --- physics/hookes_law.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/physics/hookes_law.py b/physics/hookes_law.py index d3d688d52298..e9f015503d4c 100644 --- a/physics/hookes_law.py +++ b/physics/hookes_law.py @@ -15,7 +15,7 @@ """ -def hookes_law(spring_contant: float, displacement: float) -> float: +def hookes_law(spring_constant: float, displacement: float) -> float: """ Calculate the Hookes law from the given values of spring constant 'k' and the displacement 'x' from the equilibrium position.