{"record":{"id":"6f8768c0bd339c33","repo":"TheAlgorithms/Python","slug":"inductive-reactance-cannot-be-negative","errorCode":null,"errorMessage":"Inductive reactance cannot be negative","messagePattern":"Inductive reactance cannot be negative","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"electronics/ind_reactance.py","lineNumber":55,"sourceCode":"    >>> 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\n\n    doctest.testmod()\n","sourceCodeStart":37,"sourceCodeEnd":70,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/electronics/ind_reactance.py#L37-L70","documentation":"Thrown by ind_reactance() when the reactance argument is negative. Inductive reactance X_L = 2*pi*f*L is non-negative for non-negative f and L, so a negative reactance input is rejected before the function solves for inductance or frequency.","triggerScenarios":"ind_reactance(0, 1e3, -50) or ind_reactance(35e-3, 0, -10) — any call where reactance < 0 and exactly one argument equals 0.","commonSituations":"Feeding impedance-meter output where a negative sign denotes capacitive vs inductive reactance; reusing values computed for capacitive reactance (X_C = 1/(2*pi*f*C)) which can carry sign conventions; data-entry sign errors.","solutions":["Pass reactance as a non-negative magnitude; use abs(reactance) if the sign only encoded inductive/capacitive kind.","If your source uses signed reactance, convert first: negative means capacitive — consider cap_reactance-style handling instead.","Guard reactance >= 0 in input validation before calling."],"exampleFix":"# before\nind_reactance(0, 1e3, -50)  # ValueError: Inductive reactance cannot be negative\n\n# after\nind_reactance(0, 1e3, abs(-50))  # {'inductance': 0.007957747154594767}","handlingStrategy":"validation","validationCode":"if reactance < 0:\n    raise ValueError('inductive reactance must be >= 0')","typeGuard":"def valid_inductive_reactance(x: float) -> bool:\n    return x >= 0","tryCatchPattern":"try:\n    out = ind_reactance(l, f, x)\nexcept ValueError as exc:\n    if 'reactance cannot be negative' in str(exc):\n        # negative reactance usually means CAPACITIVE: route accordingly\n        ...\n    raise","preventionTips":["Convert signed reactance to magnitude + kind before calling.","Negative reactance from meters usually denotes capacitance — handle separately.","Validate X_L >= 0 at the boundary."],"tags":["electronics","validation","reactance","valueerror"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}