TheAlgorithms/Python · error · ValueError
You cannot supply more or less than 2 values
Error message
You cannot supply more or less than 2 values
What it means
Raised by shear_stress(stress, tangential_force, area) in physics/shear_stress.py when the number of arguments equal to 0 among the three is not exactly one. Like gravitational_law, it is a solver: you supply two known values and 0 as the placeholder for the unknown (stress = F/A family), and it returns a (name, value) tuple.
Source
Thrown at physics/shear_stress.py:32
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 (View on GitHub (pinned to f5988cc097)
Solutions
- Pass exactly one argument as 0 for the quantity you want computed, e.g. shear_stress(stress=0, tangential_force=1600, area=200) -> ('stress', 8.0)
- Unpack the returned tuple: name, value = shear_stress(...)
- If validating known triples, write your own stress == tangential_force/area check instead of calling the solver
Example fix
# before
shear_stress(stress=25, tangential_force=100, area=50)
# ValueError: You cannot supply more or less than 2 values
# after
name, area = shear_stress(stress=25, tangential_force=100, area=0)
# -> ('area', 4.0) Defensive patterns
Strategy: validation
Validate before calling
n = sum(v == 0 for v in (stress, tangential_force, area))
if n != 1:
raise ValueError(f"exactly one argument must be 0 (the unknown), got {n}")
name, value = shear_stress(stress, tangential_force, area) Type guard
def has_single_zero(*vals) -> bool:
return sum(v == 0 for v in vals) == 1 Try / catch
try:
result = shear_stress(s, f, a)
except ValueError as e:
if "more or less than 2" in str(e):
result = None # re-ask user for exactly two knowns + one 0
else:
raise Prevention
- This is a solver: supply two knowns and exactly one 0 for the unknown
- Unpack the (name, value) tuple return, not a bare float
- Do not pass all three knowns — validate consistency yourself instead
When it happens
Trigger: shear_stress(stress=25, tangential_force=100, area=50) — no zero, nothing to solve; shear_stress(stress=0, tangential_force=0, area=200) — two zeros; shear_stress(stress=0, tangential_force=0, area=0).
Common situations: Expecting a plain calculator (pass all three knowns) instead of a solver; UIs mapping multiple empty fields to 0; porting code that used None as the unknown sentinel.
Related errors
- One and only one argument must be 0
- Expected a_coeffs to have {self.order + 1} elements for {sel
- n must not be negative
- Candidates list should not be empty
- Depth cannot be less than 0
AI-assisted analysis of TheAlgorithms/Python@f5988cc097 (2026-08-14).
Data as JSON: /api/errors/bc35191d11fdbc60.
Report an issue: GitHub.