{"record":{"id":"e4c1e54d13666bdf","repo":"TheAlgorithms/Python","slug":"resistance-must-be-positive","errorCode":null,"errorMessage":"Resistance must be positive.","messagePattern":"Resistance must be positive\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"electronics/charging_capacitor.py","lineNumber":63,"sourceCode":"    Traceback (most recent call last):\n        ...\n    ValueError: Source voltage must be positive.\n\n    >>> charging_capacitor(source_voltage=20,resistance=-2000,capacitance=30,time_sec=4)\n    Traceback (most recent call last):\n        ...\n    ValueError: Resistance must be positive.\n\n    >>> charging_capacitor(source_voltage=30,resistance=1500,capacitance=0,time_sec=4)\n    Traceback (most recent call last):\n        ...\n    ValueError: Capacitance 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 capacitance <= 0:\n        raise ValueError(\"Capacitance must be positive.\")\n    return round(source_voltage * (1 - exp(-time_sec / (resistance * capacitance))), 3)\n\n\nif __name__ == \"__main__\":\n    import doctest\n\n    doctest.testmod()\n","sourceCodeStart":45,"sourceCodeEnd":73,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/electronics/charging_capacitor.py#L45-L73","documentation":"Thrown by charging_capacitor() when resistance <= 0. The RC time constant tau = R*C appears in the exponent of the charging curve; zero or negative resistance makes the model undefined (instant/inverted charging), so the library rejects it.","triggerScenarios":"charging_capacitor(source_voltage=20, resistance=-2000, capacitance=30, time_sec=4) or resistance=0. This check runs after the source-voltage check.","commonSituations":"Ideal-wire assumptions (R=0) carried over from schematic simplifications; unit confusion (kOhm vs Ohm) leading to negative/zero computed values; parameter-order mix-ups.","solutions":["Use a strictly positive resistance, e.g. the actual series resistor value in ohms.","If you assumed an ideal circuit with no resistor, this model cannot represent it — add a realistic ESR/series resistance.","Verify keyword arguments; positional calls easily swap resistance and capacitance."],"exampleFix":"# before\ncharging_capacitor(source_voltage=20, resistance=-2000, capacitance=30, time_sec=4)\n\n# after\ncharging_capacitor(source_voltage=20, resistance=2000, capacitance=30, time_sec=4)","handlingStrategy":"validation","validationCode":"if resistance <= 0:\n    raise ValueError(\"resistance must be positive\")\nv = charging_capacitor(source_voltage, resistance, capacitance, time_sec)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never assume R=0; include ESR or winding resistance.","Double-check ohm-unit conversions before the call."],"tags":["electronics","rc-circuit","physics","validation","sign-error"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}