{"record":{"id":"cff63c7df5683191","repo":"TheAlgorithms/Python","slug":"acceptor-concentration-should-be-positive","errorCode":null,"errorMessage":"Acceptor concentration should be positive","messagePattern":"Acceptor concentration should be positive","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"electronics/builtin_voltage.py","lineNumber":44,"sourceCode":"    ValueError: Acceptor concentration should be positive\n    >>> builtin_voltage(donor_conc=1000, acceptor_conc=1000, intrinsic_conc=0)\n    Traceback (most recent call last):\n      ...\n    ValueError: Intrinsic concentration should be positive\n    >>> builtin_voltage(donor_conc=1000, acceptor_conc=3000, intrinsic_conc=2000)\n    Traceback (most recent call last):\n      ...\n    ValueError: Donor concentration should be greater than intrinsic concentration\n    >>> builtin_voltage(donor_conc=3000, acceptor_conc=1000, intrinsic_conc=2000)\n    Traceback (most recent call last):\n      ...\n    ValueError: Acceptor concentration should be greater than intrinsic concentration\n    \"\"\"\n\n    if donor_conc <= 0:\n        raise ValueError(\"Donor concentration should be positive\")\n    elif acceptor_conc <= 0:\n        raise ValueError(\"Acceptor concentration should be positive\")\n    elif intrinsic_conc <= 0:\n        raise ValueError(\"Intrinsic concentration should be positive\")\n    elif donor_conc <= intrinsic_conc:\n        raise ValueError(\n            \"Donor concentration should be greater than intrinsic concentration\"\n        )\n    elif acceptor_conc <= intrinsic_conc:\n        raise ValueError(\n            \"Acceptor concentration should be greater than intrinsic concentration\"\n        )\n    else:\n        return (\n            Boltzmann\n            * T\n            * log((donor_conc * acceptor_conc) / intrinsic_conc**2)\n            / physical_constants[\"electron volt\"][0]\n        )\n","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/electronics/builtin_voltage.py#L26-L62","documentation":"Raised by builtin_voltage() when acceptor_conc <= 0 while donor_conc is positive. Na appears in the numerator of ln(Nd*Na/ni^2), so a non-positive acceptor doping makes the logarithm undefined. It is the second check in the ordered chain, so donor_conc must already be > 0 for this specific message to appear.","triggerScenarios":"Calling builtin_voltage(donor_conc=1e16, acceptor_conc=-5, ...) or acceptor_conc=0. If donor_conc is also <= 0, error 254 fires first and this message never appears.","commonSituations":"Symmetric doping variables where only one was populated; copy-paste parameter lists leaving acceptor_conc at a 0 default; sign errors in data ingestion from measurement files.","solutions":["Supply a positive acceptor concentration (Na > 0, typically 1e14-1e19 cm^-3).","Audit both doping parameters together before the call: if nd <= 0 or na <= 0: raise with context.","Validate imported data rows and drop/flag rows with non-positive concentrations."],"exampleFix":"# before\nbuiltin_voltage(donor_conc=1e16, acceptor_conc=0.0, intrinsic_conc=1e10)  # ValueError\n\n# after\nbuiltin_voltage(donor_conc=1e16, acceptor_conc=1e15, intrinsic_conc=1e10)","handlingStrategy":"validation","validationCode":"def positive(x: float) -> bool:\n    return x > 0\n\ndef valid_doping(nd: float, na: float, ni: float) -> bool:\n    return nd > 0 and na > 0 and ni > 0","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Populate both Nd and Na together from the same data row.","Reject 0/None concentrations during data import.","Keep symmetric parameter handling for donor and acceptor."],"tags":["electronics","physics","input-validation"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}