{"record":{"id":"ee43c00cae6987e1","repo":"TheAlgorithms/Python","slug":"exactly-one-argument-must-be-0-ee43c0","errorCode":null,"errorMessage":"Exactly one argument must be 0","messagePattern":"Exactly one argument must be 0","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"info","filePath":"electronics/ohms_law.py","lineNumber":36,"sourceCode":"      ...\n    ValueError: Resistance cannot be negative\n    >>> ohms_law(resistance=0, voltage=-10, current=1)\n    {'resistance': -10.0}\n    >>> ohms_law(voltage=0, current=-1.5, resistance=2)\n    {'voltage': -3.0}\n    \"\"\"\n    if (voltage, current, resistance).count(0) != 1:\n        raise ValueError(\"One and only one argument must be 0\")\n    if resistance < 0:\n        raise ValueError(\"Resistance cannot be negative\")\n    if voltage == 0:\n        return {\"voltage\": float(current * resistance)}\n    elif current == 0:\n        return {\"current\": voltage / resistance}\n    elif resistance == 0:\n        return {\"resistance\": voltage / current}\n    else:\n        raise ValueError(\"Exactly one argument must be 0\")\n\n\nif __name__ == \"__main__\":\n    import doctest\n\n    doctest.testmod()\n","sourceCodeStart":18,"sourceCodeEnd":43,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/electronics/ohms_law.py#L18-L43","documentation":"The final else branch of ohms_law() raises 'Exactly one argument must be 0'. It is unreachable: the opening guard `(voltage, current, resistance).count(0) != 1` already raises for every input lacking exactly one zero, so one of voltage==0 / current==0 / resistance==0 always matches afterwards. The branch is defensive residue and its message differs from the primary guard's ('One and only one argument must be 0').","triggerScenarios":"Not reachable via any real inputs; would only execute if the leading count guard were removed or altered.","commonSituations":"Encountered during source review, refactors, or when aiming for 100% branch coverage; forks that delete the first guard will see the divergent message.","solutions":["Callers need no action — the primary ValueError with the 'One and only one...' message is what fires in practice.","Maintainers: drop the unreachable else or unify the message text with the primary guard.","Coverage tooling: treat as unreachable code, not a test gap."],"exampleFix":"# before\n    elif resistance == 0:\n        return {\"resistance\": voltage / current}\n    else:\n        raise ValueError(\"Exactly one argument must be 0\")\n\n# after\n    else:  # resistance == 0, the only remaining case\n        return {\"resistance\": voltage / current}","handlingStrategy":"validation","validationCode":"# Guard the reachable primary error instead:\nassert (voltage, current, resistance).count(0) == 1","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Unreachable branch; target the 'One and only one argument must be 0' error in handling code.","Do not write tests for this exact message via public inputs."],"tags":["electronics","dead-code","defensive-programming","ohms-law"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}