{"record":{"id":"ca0c0fdff924bafd","repo":"TheAlgorithms/Python","slug":"conductivity-cannot-be-negative","errorCode":null,"errorMessage":"Conductivity cannot be negative","messagePattern":"Conductivity cannot be negative","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"electronics/electric_conductivity.py","lineNumber":48,"sourceCode":"        ...\n    ValueError: Electron concentration cannot be negative\n    >>> electric_conductivity(conductivity=50, electron_conc=0, mobility=-10)\n    Traceback (most recent call last):\n        ...\n    ValueError: mobility cannot be negative\n    >>> electric_conductivity(conductivity=50, electron_conc=0, mobility=0)\n    Traceback (most recent call last):\n        ...\n    ValueError: You cannot supply more or less than 2 values\n    >>> electric_conductivity(conductivity=50, electron_conc=200, mobility=300)\n    Traceback (most recent call last):\n        ...\n    ValueError: You cannot supply more or less than 2 values\n    \"\"\"\n    if (conductivity, electron_conc, mobility).count(0) != 1:\n        raise ValueError(\"You cannot supply more or less than 2 values\")\n    elif conductivity < 0:\n        raise ValueError(\"Conductivity cannot be negative\")\n    elif electron_conc < 0:\n        raise ValueError(\"Electron concentration cannot be negative\")\n    elif mobility < 0:\n        raise ValueError(\"mobility cannot be negative\")\n    elif conductivity == 0:\n        return (\n            \"conductivity\",\n            mobility * electron_conc * ELECTRON_CHARGE,\n        )\n    elif electron_conc == 0:\n        return (\n            \"electron_conc\",\n            conductivity / (mobility * ELECTRON_CHARGE),\n        )\n    else:\n        return (\n            \"mobility\",\n            conductivity / (electron_conc * ELECTRON_CHARGE),","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/electronics/electric_conductivity.py#L30-L66","documentation":"Thrown by electric_conductivity() when conductivity < 0 while exactly one argument is 0. Electrical conductivity sigma is a non-negative material property (S/m); a negative value is non-physical and is rejected before the sigma = n*e*mu relation is applied.","triggerScenarios":"electric_conductivity(conductivity=-50, electron_conc=200, mobility=0) — valid zero-count but negative conductivity.","commonSituations":"Instrument noise around zero on a four-point-probe measurement; sign flips when deriving conductivity as 1/resistivity with inverted operands; spreadsheet import artifacts.","solutions":["Pass a non-negative conductivity (typical metals: ~1e7 S/m; silicon: ~1e-4 to 1e3 S/m depending on doping).","Validate measurement data at ingestion and reject negatives before they reach the library.","If conductivity is the unknown you want computed, pass 0 for it instead of a negative placeholder."],"exampleFix":"# before\nelectric_conductivity(conductivity=-50, electron_conc=200, mobility=0)\n\n# after\nelectric_conductivity(conductivity=50, electron_conc=200, mobility=0)","handlingStrategy":"validation","validationCode":"if conductivity < 0:\n    raise ValueError(\"conductivity must be >= 0\")\nname, value = electric_conductivity(conductivity, electron_conc, mobility)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Compute conductivity as positive 1/resistivity.","Range-check measured conductivity against material tables."],"tags":["electronics","semiconductor","physics","validation","sign-error"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}