{"record":{"id":"2d397d09f37638c7","repo":"TheAlgorithms/Python","slug":"one-and-only-one-argument-must-be-0-2d397d","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/ind_reactance.py","lineNumber":49,"sourceCode":"\n    >>> ind_reactance(35e-6, 0, -1)\n    Traceback (most recent call last):\n        ...\n    ValueError: Inductive reactance cannot be negative\n\n    >>> ind_reactance(0, 10e3, 50)\n    {'inductance': 0.0007957747154594767}\n\n    >>> ind_reactance(35e-3, 0, 50)\n    {'frequency': 227.36420441699332}\n\n    >>> ind_reactance(35e-6, 1e3, 0)\n    {'reactance': 0.2199114857512855}\n\n    \"\"\"\n\n    if (inductance, frequency, reactance).count(0) != 1:\n        raise ValueError(\"One and only one argument must be 0\")\n    if inductance < 0:\n        raise ValueError(\"Inductance cannot be negative\")\n    if frequency < 0:\n        raise ValueError(\"Frequency cannot be negative\")\n    if reactance < 0:\n        raise ValueError(\"Inductive reactance cannot be negative\")\n    if inductance == 0:\n        return {\"inductance\": reactance / (2 * pi * frequency)}\n    elif frequency == 0:\n        return {\"frequency\": reactance / (2 * pi * inductance)}\n    elif reactance == 0:\n        return {\"reactance\": 2 * pi * frequency * inductance}\n    else:\n        raise ValueError(\"Exactly one argument must be 0\")\n\n\nif __name__ == \"__main__\":\n    import doctest","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/electronics/ind_reactance.py#L31-L67","documentation":"Thrown by ind_reactance() in electronics/ind_reactance.py when the count of zero arguments among (inductance, frequency, reactance) is not exactly one. The function solves X_L = 2*pi*f*L for whichever quantity is 0, so 0 acts as the sentinel meaning 'this is the unknown'; supplying all non-zero values or more than one zero is ambiguous.","triggerScenarios":"ind_reactance(35e-3, 1e3, 50) (all known, nothing to solve); ind_reactance(0, 0, 50) (two zeros, underdetermined); passing None or -1 instead of 0 as the unknown marker.","commonSituations":"Passing a full triple of measured values from an instrument dump; forgetting the sentinel convention when migrating from an API that used None; looping over rows where some rows have all fields populated.","solutions":["Set exactly one argument to 0 to mark the unknown: ind_reactance(35e-6, 1e3, 0) -> {'reactance': 0.2199114857512855}.","Pre-check (inductance, frequency, reactance).count(0) == 1 before calling when inputs are dynamic.","Do not call the function when you already have all three values — it is a solver, not a verifier."],"exampleFix":"# before\nind_reactance(35e-3, 1e3, 50)  # ValueError: One and only one argument must be 0\n\n# after\nx_l = ind_reactance(35e-3, 1e3, 0)['reactance']  # solve for reactance","handlingStrategy":"validation","validationCode":"if (inductance, frequency, reactance).count(0) != 1:\n    raise ValueError('exactly one of L/f/XL must be 0 (the unknown)')","typeGuard":"def has_single_unknown(l: float, f: float, x: float) -> bool:\n    return (l, f, x).count(0) == 1","tryCatchPattern":"try:\n    out = ind_reactance(l, f, x)\nexcept ValueError as exc:\n    if 'must be 0' in str(exc):\n        # fix the sentinel pattern, do not retry blindly\n        ...\n    raise","preventionTips":["0 is the 'unknown' sentinel — supply exactly one.","Don't feed fully-populated instrument rows straight in.","Use None-based wrappers that convert None to 0 for exactly one field."],"tags":["electronics","validation","reactance","inductance","valueerror"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}