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
Thrown by electric_conductivity() in electronics/electric_conductivity.py when the number of zeros among (conductivity, electron_conc, mobility) is not exactly 1. The function solves sigma = n*e*mu for the single unknown, signaled by passing 0 for that argument; supplying zero for none or several arguments is ambiguous.
Source
Thrown at electronics/electric_conductivity.py:46
>>> electric_conductivity(conductivity=50, electron_conc=-10, mobility=0)
Traceback (most recent call last):
...
ValueError: Electron concentration cannot be negative
>>> electric_conductivity(conductivity=50, electron_conc=0, mobility=-10)
Traceback (most recent call last):
...
ValueError: mobility cannot be negative
>>> electric_conductivity(conductivity=50, electron_conc=0, mobility=0)
Traceback (most recent call last):
...
ValueError: You cannot supply more or less than 2 values
>>> electric_conductivity(conductivity=50, electron_conc=200, mobility=300)
Traceback (most recent call last):
...
ValueError: You cannot supply more or less than 2 values
"""
if (conductivity, electron_conc, mobility).count(0) != 1:
raise ValueError("You cannot supply more or less than 2 values")
elif conductivity < 0:
raise ValueError("Conductivity cannot be negative")
elif electron_conc < 0:
raise ValueError("Electron concentration cannot be negative")
elif mobility < 0:
raise ValueError("mobility cannot be negative")
elif conductivity == 0:
return (
"conductivity",
mobility * electron_conc * ELECTRON_CHARGE,
)
elif electron_conc == 0:
return (
"electron_conc",
conductivity / (mobility * ELECTRON_CHARGE),
)
else:
return (View on GitHub (pinned to f5988cc097)
Solutions
- Pass exactly one argument as 0 (the unknown) and positive values for the other two.
- Read the function's docstring doctests to confirm the intended calling convention before wiring calls.
- Wrap the call with a helper that takes explicit 'solve_for' semantics if the 0-marker convention is error-prone in your codebase.
Example fix
# before
electric_conductivity(conductivity=50, electron_conc=200, mobility=300) # no unknown
# after
electric_conductivity(conductivity=0, electron_conc=200, mobility=300)
# -> ('conductivity', ...) Defensive patterns
Strategy: validation
Validate before calling
args = (conductivity, electron_conc, mobility)
if args.count(0) != 1:
raise ValueError("pass exactly one 0 as the unknown")
name, value = electric_conductivity(*args) Prevention
- Same 0-means-unknown convention as carrier_concentration and electric_power.
- Write a thin wrapper with solve_for='conductivity' semantics to avoid sentinel mistakes.
When it happens
Trigger: electric_conductivity(conductivity=50, electron_conc=0, mobility=0) (two zeros) or electric_conductivity(conductivity=50, electron_conc=200, mobility=300) (no zero).
Common situations: Assuming all three arguments are required and passing measured values for each; None-coalescing to 0 defaults; confusion of the '0 means solve-for-this' convention shared by several functions in this electronics package.
Related errors
- You cannot supply more or less than 2 values
- Electron concentration cannot be negative in a semiconductor
- Hole concentration cannot be negative in a semiconductor
- Intrinsic concentration cannot be negative in a semiconducto
- One and only one argument must be 0
AI-assisted analysis of TheAlgorithms/Python@f5988cc097 (2026-08-14).
Data as JSON: /api/errors/53dc824e1fe4c9a4.
Report an issue: GitHub.