forked from TheAlgorithms/Python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
shear_stress.py
59 lines (52 loc) · 1.59 KB
/
shear_stress.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from __future__ import annotations
"""
Shear stress is a component of stress that is coplanar to the material cross-section.
It arises due to a shear force, the component of the force vector parallel to the
material cross-section.
https://en.wikipedia.org/wiki/Shear_stress
"""
def shear_stress(
stress: float,
tangential_force: float,
area: float,
) -> tuple[str, float]:
"""
This function can calculate any one of the three -
1. Shear Stress
2. Tangential Force
3. Cross-sectional Area
This is calculated from the other two provided values
Examples -
>>> shear_stress(stress=25, tangential_force=100, area=0)
('area', 4.0)
>>> shear_stress(stress=0, tangential_force=1600, area=200)
('stress', 8.0)
>>> shear_stress(stress=1000, tangential_force=0, area=1200)
('tangential_force', 1200000)
"""
if (stress, tangential_force, area).count(0) != 1:
raise ValueError("You cannot supply more or less than 2 values")
elif stress < 0:
raise ValueError("Stress cannot be negative")
elif tangential_force < 0:
raise ValueError("Tangential Force cannot be negative")
elif area < 0:
raise ValueError("Area cannot be negative")
elif stress == 0:
return (
"stress",
tangential_force / area,
)
elif tangential_force == 0:
return (
"tangential_force",
stress * area,
)
else:
return (
"area",
tangential_force / stress,
)
if __name__ == "__main__":
import doctest
doctest.testmod()