Skip to content

Commit 551ed4c

Browse files
authored
Added Hooke's Law
1 parent 7530a41 commit 551ed4c

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

physics/Hookes_law.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#Hookes Law
2+
"""
3+
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.
4+
5+
Formulae : F = -k*x
6+
7+
F: Force
8+
k: Spring constant
9+
x: displacement from the equilibrium position
10+
11+
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.
12+
13+
Reference: https://en.wikipedia.org/wiki/Hooke%27s_law
14+
15+
"""
16+
17+
def hookes_law(k:float, x:float) ->float:
18+
return round(-k*x, 2)
19+
"""
20+
Calculate the Hookes law from the given values of spring constant 'k'
21+
and the displacement 'x' from the equilibrium position.
22+
23+
>>> hookes_law(200, 0.05)
24+
-10.0
25+
>>> hookes_law(50, 5)
26+
-250
27+
>>> hookes_law(300, 3)
28+
-900
29+
"""
30+
31+
32+
if __name__ == "__main__":
33+
import doctest
34+
35+
doctest.testmod()
36+
37+
38+

0 commit comments

Comments
 (0)