{"record":{"id":"242789c3579e4614","repo":"TheAlgorithms/Python","slug":"exactly-one-argument-must-be-0","errorCode":null,"errorMessage":"Exactly one argument must be 0","messagePattern":"Exactly one argument must be 0","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"warning","filePath":"electronics/coulombs_law.py","lineNumber":79,"sourceCode":"    charge_product = abs(charge1 * charge2)\n\n    if (force, charge1, charge2, distance).count(0) != 1:\n        raise ValueError(\"One and only one argument must be 0\")\n    if distance < 0:\n        raise ValueError(\"Distance cannot be negative\")\n    if force == 0:\n        force = COULOMBS_CONSTANT * charge_product / (distance**2)\n        return {\"force\": force}\n    elif charge1 == 0:\n        charge1 = abs(force) * (distance**2) / (COULOMBS_CONSTANT * charge2)\n        return {\"charge1\": charge1}\n    elif charge2 == 0:\n        charge2 = abs(force) * (distance**2) / (COULOMBS_CONSTANT * charge1)\n        return {\"charge2\": charge2}\n    elif distance == 0:\n        distance = (COULOMBS_CONSTANT * charge_product / abs(force)) ** 0.5\n        return {\"distance\": distance}\n    raise ValueError(\"Exactly one argument must be 0\")\n\n\nif __name__ == \"__main__\":\n    import doctest\n\n    doctest.testmod()\n","sourceCodeStart":61,"sourceCodeEnd":86,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/electronics/coulombs_law.py#L61-L86","documentation":"Defensive trailing raise at the end of couloumbs_law(): if none of the four elif branches matched, the solver fell through. In practice this line is unreachable — the earlier count(0) != 1 check guarantees exactly one argument is 0 and the elif chain (force/charge1/charge2/distance == 0) covers all four cases — so seeing it indicates the guard logic was modified or bypassed.","triggerScenarios":"Not reachable through the public API as shipped. Could fire if someone edits the function to remove or reorder the count(0) check or the elif branches.","commonSituations":"Forked/patched copies of the file where validation was loosened; copy-pasting the solver body into new code without copying the precondition check.","solutions":["If you hit this, restore the original precondition: exactly one of (force, charge1, charge2, distance) must be 0.","Do not copy the elif chain without the count(0) != 1 guard that precedes it.","Treat it as an invariant assertion failure — audit any local modifications to coulombs_law.py."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    result = couloumbs_law(force, charge1, charge2, distance)\nexcept ValueError as e:\n    if \"Exactly one argument must be 0\" in str(e):\n        raise RuntimeError(\"invariant broken — coulombs_law.py was modified\") from e\n    raise","preventionTips":["Do not fork the solver without its count(0) != 1 precondition.","Treat this message as an internal invariant failure, not a user-input error."],"tags":["electronics","electrostatics","dead-code","invariant","defensive"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}