{"record":{"id":"6467433aebcee2f6","repo":"TheAlgorithms/Python","slug":"inductance-must-be-positive","errorCode":null,"errorMessage":"Inductance must be positive.","messagePattern":"Inductance must be positive\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"electronics/charging_inductor.py","lineNumber":88,"sourceCode":"    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":70,"sourceCodeEnd":98,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/electronics/charging_inductor.py#L70-L98","documentation":"Thrown by charging_inductor() when inductance <= 0. Inductance appears in the exponent (-t*R/L); zero or negative L is non-physical for an RL charging model and would divide by zero or invert the curve, so it is rejected (last of three sequential guards).","triggerScenarios":"charging_inductor(source_voltage=15, resistance=25, inductance=0, time=5) or any negative inductance.","commonSituations":"Unit errors (mH/uH/nH vs H) collapsing to 0; forgetting to convert a datasheet value; passing a component count or tolerance percentage instead of henries.","solutions":["Pass inductance in henries as a positive number (e.g. 0.001 for 1 mH).","Validate unit conversion at your data boundary before calling.","Remember source_voltage and resistance already passed their checks when you see this error."],"exampleFix":"# before\ncharging_inductor(source_voltage=15, resistance=25, inductance=0, time=5)\n\n# after\ncharging_inductor(source_voltage=15, resistance=25, inductance=0.02, time=5)","handlingStrategy":"validation","validationCode":"if inductance <= 0:\n    raise ValueError(\"inductance must be positive henries\")\ni = charging_inductor(source_voltage, resistance, inductance, time)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Convert mH/uH/nH to henries explicitly.","Keep a single unit-normalization helper for all component values."],"tags":["electronics","rl-circuit","physics","validation","unit-error"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}