{"record":{"id":"3b9e0bfee3707afb","repo":"TheAlgorithms/Python","slug":"one-and-only-one-argument-must-be-0-3b9e0b","errorCode":null,"errorMessage":"One and only one argument must be 0","messagePattern":"One and only one argument must be 0","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"electronics/electrical_impedance.py","lineNumber":32,"sourceCode":") -> dict[str, float]:\n    \"\"\"\n    Apply Electrical Impedance formula, on any two given electrical values,\n    which can be resistance, reactance, and impedance, and then in a Python dict\n    return name/value pair of the zero value.\n\n    >>> electrical_impedance(3,4,0)\n    {'impedance': 5.0}\n    >>> 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":14,"sourceCodeEnd":47,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/electronics/electrical_impedance.py#L14-L47","documentation":"Thrown by electrical_impedance() in electronics/electrical_impedance.py when the number of arguments equal to 0 among (resistance, reactance, impedance) is not exactly one. The function uses the 0-valued argument as the 'unknown' to solve for via the Pythagorean relation Z^2 = R^2 + X^2, so exactly one argument must be 0 as the sentinel for the missing quantity.","triggerScenarios":"electrical_impedance(3, 4, 5) (no argument is 0, nothing to solve for); electrical_impedance(0, 0, 5) or electrical_impedance(0, 4, 0) (two or more zeros, ambiguous/underdetermined).","commonSituations":"Treating the function as a general validator and passing all three measured values; using None or -1 instead of 0 as the 'unknown' placeholder; copying example calls that omit the sentinel zero.","solutions":["Set exactly one of resistance/reactance/impedance to 0 to indicate the unknown: electrical_impedance(3, 4, 0) -> {'impedance': 5.0}.","If all three values are known, do not call the function — it is a solver, not a checker.","Check (resistance, reactance, impedance).count(0) == 1 before calling in dynamic code."],"exampleFix":"# before\nelectrical_impedance(3, 4, 5)  # ValueError: One and only one argument must be 0\n\n# after\nz = electrical_impedance(3, 4, 0)  # solve for impedance -> 5.0","handlingStrategy":"validation","validationCode":"if (resistance, reactance, impedance).count(0) != 1:\n    raise ValueError('exactly one of resistance/reactance/impedance must be 0')","typeGuard":"def has_single_unknown(r: float, x: float, z: float) -> bool:\n    return (r, x, z).count(0) == 1","tryCatchPattern":"try:\n    result = electrical_impedance(r, x, z)\nexcept ValueError as exc:\n    if 'must be 0' in str(exc):\n        # caller supplied wrong sentinel pattern\n        ...\n    raise","preventionTips":["Remember 0 means 'unknown' in this API, not zero ohms.","Never call with all three values known.","Use the count(0)==1 helper before dynamic calls."],"tags":["electronics","validation","impedance","valueerror"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}