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 carrier_concentration() in electronics/carrier_concentration.py when the number of zeros among (electron_conc, hole_conc, intrinsic_conc) is not exactly 1. The function solves the mass-action law n*p = ni^2 for the single unknown, which the caller signals by passing 0 for that argument; supplying zero for none or for more than one argument is ambiguous.
Source
Thrown at electronics/carrier_concentration.py:44
>>> carrier_concentration(electron_conc=1000, hole_conc=400, intrinsic_conc=1200)
Traceback (most recent call last):
...
ValueError: You cannot supply more or less than 2 values
>>> carrier_concentration(electron_conc=-1000, hole_conc=0, intrinsic_conc=1200)
Traceback (most recent call last):
...
ValueError: Electron concentration cannot be negative in a semiconductor
>>> carrier_concentration(electron_conc=0, hole_conc=-400, intrinsic_conc=1200)
Traceback (most recent call last):
...
ValueError: Hole concentration cannot be negative in a semiconductor
>>> carrier_concentration(electron_conc=0, hole_conc=400, intrinsic_conc=-1200)
Traceback (most recent call last):
...
ValueError: Intrinsic concentration cannot be negative in a semiconductor
"""
if (electron_conc, hole_conc, intrinsic_conc).count(0) != 1:
raise ValueError("You cannot supply more or less than 2 values")
elif electron_conc < 0:
raise ValueError("Electron concentration cannot be negative in a semiconductor")
elif hole_conc < 0:
raise ValueError("Hole concentration cannot be negative in a semiconductor")
elif intrinsic_conc < 0:
raise ValueError(
"Intrinsic concentration cannot be negative in a semiconductor"
)
elif electron_conc == 0:
return (
"electron_conc",
intrinsic_conc**2 / hole_conc,
)
elif hole_conc == 0:
return (
"hole_conc",
intrinsic_conc**2 / electron_conc,
)View on GitHub (pinned to f5988cc097)
Solutions
- Pass exactly one argument as 0 — the one you want the function to compute — and real positive values for the other two.
- If you genuinely meant a physical zero concentration, this API cannot model it; compute the mass-action result yourself instead.
- Double-check argument order/keywords; positional mix-ups frequently leave all three non-zero.
Example fix
# before
carrier_concentration(electron_conc=100, hole_conc=200, intrinsic_conc=1200) # no unknown
# after
carrier_concentration(electron_conc=0, hole_conc=200, intrinsic_conc=1200)
# -> ('electron_conc', 7200.0) Defensive patterns
Strategy: validation
Validate before calling
args = (electron_conc, hole_conc, intrinsic_conc)
if args.count(0) != 1:
raise ValueError("pass exactly one 0 as the unknown")
name, value = carrier_concentration(*args) Prevention
- Remember the package-wide convention: 0 marks the argument to solve for.
- Call with keyword arguments to make the unknown explicit.
- Wrap the API in your own function with an explicit solve_for parameter.
When it happens
Trigger: carrier_concentration(electron_conc=0, hole_conc=0, intrinsic_conc=1200) (two zeros), or carrier_concentration(electron_conc=100, hole_conc=200, intrinsic_conc=1200) (no zero). Note that 0 here means 'unknown', not a physical zero.
Common situations: Assuming 0 is a legitimate physical concentration (doped semiconductor with no holes); migrating from an API where all three arguments were required and computed; passing None-coalesced defaults of 0.
Related errors
- Capacitor at index {index} has a negative or zero value!
- Electron concentration cannot be negative in a semiconductor
- Hole concentration cannot be negative in a semiconductor
- Intrinsic concentration cannot be negative in a semiconducto
- Source voltage must be positive.
AI-assisted analysis of TheAlgorithms/Python@f5988cc097 (2026-08-14).
Data as JSON: /api/errors/d5543b4d349eeb4e.
Report an issue: GitHub.