TheAlgorithms/Python · info · ValueError
Exactly one argument must be 0
Error message
Exactly one argument must be 0
What it means
The final else branch of ind_reactance() raises 'Exactly one argument must be 0'. It is unreachable defensive code: the leading guard `(inductance, frequency, reactance).count(0) != 1` already raises for any input without exactly one zero, so after the three negativity checks one of inductance==0 / frequency==0 / reactance==0 must hold. It exists only as a safety net, and its message text differs from the primary guard's.
Source
Thrown at electronics/ind_reactance.py:63
"""
if (inductance, frequency, reactance).count(0) != 1:
raise ValueError("One and only one argument must be 0")
if inductance < 0:
raise ValueError("Inductance cannot be negative")
if frequency < 0:
raise ValueError("Frequency cannot be negative")
if reactance < 0:
raise ValueError("Inductive reactance cannot be negative")
if inductance == 0:
return {"inductance": reactance / (2 * pi * frequency)}
elif frequency == 0:
return {"frequency": reactance / (2 * pi * inductance)}
elif reactance == 0:
return {"reactance": 2 * pi * frequency * inductance}
else:
raise ValueError("Exactly one argument must be 0")
if __name__ == "__main__":
import doctest
doctest.testmod()
View on GitHub (pinned to f5988cc097)
Solutions
- No caller action required — the primary ValueError('One and only one argument must be 0') is the one you will observe.
- Maintainers: remove the unreachable else or unify its message with the primary guard.
- Test suites: exclude this branch from coverage targets rather than contorting inputs to reach it.
Example fix
# before
elif reactance == 0:
return {"reactance": 2 * pi * frequency * inductance}
else:
raise ValueError("Exactly one argument must be 0")
# after
else: # reactance == 0, the only remaining case
return {"reactance": 2 * pi * frequency * inductance} Defensive patterns
Strategy: validation
Validate before calling
# Guard the reachable primary error instead: assert (inductance, frequency, reactance).count(0) == 1
Prevention
- Branch is unreachable; test against the 'One and only one argument must be 0' error instead.
- Never assert on the 'Exactly one argument must be 0' message — public input cannot produce it.
When it happens
Trigger: Cannot be triggered through the public API for any real inputs; only relevant if the initial count guard is removed/modified or in exhaustive branch-coverage tooling.
Common situations: Seen during code review, refactoring, or coverage/mutation testing; a fork that relaxes the first guard would surface the inconsistent second message.
Related errors
- Exactly one argument must be 0
- Exactly one argument must be 0
- Exactly one argument must be 0
- One and only one argument must be 0
- Inductance cannot be negative
AI-assisted analysis of TheAlgorithms/Python@f5988cc097 (2026-08-14).
Data as JSON: /api/errors/1823da317a084329.
Report an issue: GitHub.