{"record":{"id":"9685570b5a459f5f","repo":"TheAlgorithms/Python","slug":"exactly-one-argument-must-be-0-968557","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/electrical_impedance.py","lineNumber":40,"sourceCode":"    >>> electrical_impedance(0,4,5)\n    {'resistance': 3.0}\n    >>> electrical_impedance(3,0,5)\n    {'reactance': 4.0}\n    >>> electrical_impedance(3,4,5)\n    Traceback (most recent call last):\n      ...\n    ValueError: One and only one argument must be 0\n    \"\"\"\n    if (resistance, reactance, impedance).count(0) != 1:\n        raise ValueError(\"One and only one argument must be 0\")\n    if resistance == 0:\n        return {\"resistance\": sqrt(pow(impedance, 2) - pow(reactance, 2))}\n    elif reactance == 0:\n        return {\"reactance\": sqrt(pow(impedance, 2) - pow(resistance, 2))}\n    elif impedance == 0:\n        return {\"impedance\": sqrt(pow(resistance, 2) + pow(reactance, 2))}\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":22,"sourceCodeEnd":47,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/electronics/electrical_impedance.py#L22-L47","documentation":"The trailing else branch in electrical_impedance() raises 'Exactly one argument must be 0'. It is effectively dead code: the guard `if (resistance, reactance, impedance).count(0) != 1` at the top already returns via ValueError('One and only one argument must be 0') for every input that does not have exactly one zero, so the if/elif chain (resistance==0 / reactance==0 / impedance==0) always matches and this raise can never execute. Its message also differs from the primary guard's message, which is a minor inconsistency.","triggerScenarios":"Not reachable through the public API with any float inputs; would only fire if the initial count-based guard were removed or the equality checks were changed (e.g. tolerance-based comparison).","commonSituations":"Encountered only when reading or refactoring the source, running mutation tests, or writing exhaustive branch-coverage tests; also relevant if a fork removes the first guard and inherits the divergent message.","solutions":["No action needed for callers; the earlier ValueError('One and only one argument must be 0') is what you will actually see.","If maintaining the file: delete the unreachable else or align its message with the primary guard to remove the inconsistency.","When writing branch-coverage tests, mark this branch as unreachable rather than forcing a test through it."],"exampleFix":"# before\n    elif impedance == 0:\n        return {\"impedance\": sqrt(pow(resistance, 2) + pow(reactance, 2))}\n    else:\n        raise ValueError(\"Exactly one argument must be 0\")\n\n# after\n    else:  # impedance == 0 (only remaining case after the count guard)\n        return {\"impedance\": sqrt(pow(resistance, 2) + pow(reactance, 2))}","handlingStrategy":"validation","validationCode":"# Guard the real (reachable) error instead:\nassert (resistance, reactance, impedance).count(0) == 1","typeGuard":null,"tryCatchPattern":null,"preventionTips":["This branch is unreachable; target the primary 'One and only one argument must be 0' error in tests.","Do not write tests asserting this exact message — they can never pass via public input."],"tags":["electronics","dead-code","defensive-programming","impedance"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}