Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions physics/Hookes_law.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#Hookes Law

Check failure on line 1 in physics/Hookes_law.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (N999)

physics/Hookes_law.py:1:1: N999 Invalid module name: '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.

Check failure on line 3 in physics/Hookes_law.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E501)

physics/Hookes_law.py:3:89: E501 Line too long (166 > 88)

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.

Check failure on line 11 in physics/Hookes_law.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E501)

physics/Hookes_law.py:11:89: E501 Line too long (167 > 88)

"""

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

Check failure on line 32 in physics/Hookes_law.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (W293)

physics/Hookes_law.py:32:1: W293 Blank line contains whitespace
doctest.testmod()



Loading