TheAlgorithms/Python · error · ValueError
Tangential Force cannot be negative
Error message
Tangential Force cannot be negative
What it means
Raised by shear_stress() when tangential_force is negative (and exactly one argument is 0, with stress >= 0). Force magnitude must be non-negative in this model; the check is second in the elif chain, so it fires only when stress is not negative.
Source
Thrown at physics/shear_stress.py:36
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,
)
View on GitHub (pinned to f5988cc097)
Solutions
- Pass the force magnitude: shear_stress(stress=1000, tangential_force=abs(force), area=1200)
- Strip directional signs from vector components before extracting the scalar magnitude
- Validate force >= 0 at the data boundary in load-case pipelines
Example fix
# before shear_stress(stress=1000, tangential_force=-500, area=0) # ValueError: Tangential Force cannot be negative # after shear_stress(stress=1000, tangential_force=abs(-500), area=0)
Defensive patterns
Strategy: validation
Validate before calling
if tangential_force < 0:
tangential_force = abs(tangential_force) # if sign encoded direction only
shear_stress(stress, tangential_force, area) Try / catch
try:
shear_stress(stress, tangential_force, area)
except ValueError as e:
if "Tangential Force" in str(e):
shear_stress(stress, abs(tangential_force), area)
else:
raise Prevention
- Pass force magnitude, not a signed vector component
- Strip direction from load-case tables before extracting scalar values
When it happens
Trigger: shear_stress(stress=1000, tangential_force=-500, area=0) — negative force with area as the unknown; forces from a physics engine where direction is encoded in the sign.
Common situations: Signed force vectors ( opposing loads coded negative) passed as scalars; load-case tables mixing positive/negative directions; typos in hand-entered force data.
Related errors
- Gravitational force can not be negative
- Distance can not be negative
- Mass can not be negative
- The length should be non-negative
- The mass of a body cannot be negative
AI-assisted analysis of TheAlgorithms/Python@f5988cc097 (2026-08-14).
Data as JSON: /api/errors/48d69453b280a466.
Report an issue: GitHub.