From 95736931a1fd0cec79a1700b5ad583f2c286161d Mon Sep 17 00:00:00 2001 From: Akank Pattnaik <96375225+Sonu-3@users.noreply.github.com> Date: Tue, 7 Oct 2025 18:58:52 +0530 Subject: [PATCH] Hookes Law --- physics/Hookes_law.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 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..d87c0ac76891 --- /dev/null +++ b/physics/Hookes_law.py @@ -0,0 +1,36 @@ +#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. + +""" + +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() + + +