{"record":{"id":"902d9f7db12270b4","repo":"TheAlgorithms/Python","slug":"resistance-must-be-positive-902d9f","errorCode":null,"errorMessage":"Resistance must be positive.","messagePattern":"Resistance must be positive\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"electronics/charging_inductor.py","lineNumber":86,"sourceCode":"    Traceback (most recent call last):\n        ...\n    ValueError: Source voltage must be positive.\n\n    >>> charging_inductor(source_voltage=10,resistance=0,inductance=20,time=5)\n    Traceback (most recent call last):\n        ...\n    ValueError: Resistance must be positive.\n\n    >>> charging_inductor(source_voltage=15, resistance=25, inductance=0, time=5)\n    Traceback (most recent call last):\n        ...\n    ValueError: Inductance must be positive.\n    \"\"\"\n\n    if source_voltage <= 0:\n        raise ValueError(\"Source voltage must be positive.\")\n    if resistance <= 0:\n        raise ValueError(\"Resistance must be positive.\")\n    if inductance <= 0:\n        raise ValueError(\"Inductance must be positive.\")\n    return round(\n        source_voltage / resistance * (1 - exp((-time * resistance) / inductance)), 3\n    )\n\n\nif __name__ == \"__main__\":\n    import doctest\n\n    doctest.testmod()\n","sourceCodeStart":68,"sourceCodeEnd":98,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/electronics/charging_inductor.py#L68-L98","documentation":"Thrown by charging_inductor() when resistance <= 0. Resistance sets the RL time constant L/R and the steady-state current Vs/R; zero or negative R makes the current infinite/undefined, so the library guards against it before computing.","triggerScenarios":"charging_inductor(source_voltage=10, resistance=0, inductance=20, time=5) or a negative resistance value. Runs after the source-voltage check.","commonSituations":"Ideal (lossless) inductor assumptions of R=0 — physically real inductors always have winding resistance; unit mix-ups (kOhm vs Ohm); negative-resistance models (tunnel diodes) which this API does not support.","solutions":["Use the real series/winding resistance (even milliohms) instead of 0.","If you truly need R=0, this step-response model does not apply — the current ramps linearly as V*t/L; compute that directly.","Check unit conversions and keyword spelling."],"exampleFix":"# before\ncharging_inductor(source_voltage=10, resistance=0, inductance=20, time=5)\n\n# after\ncharging_inductor(source_voltage=10, resistance=50, inductance=20, time=5)","handlingStrategy":"validation","validationCode":"if resistance <= 0:\n    raise ValueError(\"resistance must be positive; use winding resistance\")\ni = charging_inductor(source_voltage, resistance, inductance, time)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Real inductors have winding resistance — look up DCR in the datasheet.","For true R=0, compute I = V*t/L yourself instead of calling this API."],"tags":["electronics","rl-circuit","physics","validation","ideal-circuit-assumption"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}