{"record":{"id":"d5543b4d349eeb4e","repo":"TheAlgorithms/Python","slug":"you-cannot-supply-more-or-less-than-2-values","errorCode":null,"errorMessage":"You cannot supply more or less than 2 values","messagePattern":"You cannot supply more or less than 2 values","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"electronics/carrier_concentration.py","lineNumber":44,"sourceCode":"    >>> carrier_concentration(electron_conc=1000, hole_conc=400, intrinsic_conc=1200)\n    Traceback (most recent call last):\n        ...\n    ValueError: You cannot supply more or less than 2 values\n    >>> carrier_concentration(electron_conc=-1000, hole_conc=0, intrinsic_conc=1200)\n    Traceback (most recent call last):\n        ...\n    ValueError: Electron concentration cannot be negative in a semiconductor\n    >>> carrier_concentration(electron_conc=0, hole_conc=-400, intrinsic_conc=1200)\n    Traceback (most recent call last):\n        ...\n    ValueError: Hole concentration cannot be negative in a semiconductor\n    >>> carrier_concentration(electron_conc=0, hole_conc=400, intrinsic_conc=-1200)\n    Traceback (most recent call last):\n        ...\n    ValueError: Intrinsic concentration cannot be negative in a semiconductor\n    \"\"\"\n    if (electron_conc, hole_conc, intrinsic_conc).count(0) != 1:\n        raise ValueError(\"You cannot supply more or less than 2 values\")\n    elif electron_conc < 0:\n        raise ValueError(\"Electron concentration cannot be negative in a semiconductor\")\n    elif hole_conc < 0:\n        raise ValueError(\"Hole concentration cannot be negative in a semiconductor\")\n    elif intrinsic_conc < 0:\n        raise ValueError(\n            \"Intrinsic concentration cannot be negative in a semiconductor\"\n        )\n    elif electron_conc == 0:\n        return (\n            \"electron_conc\",\n            intrinsic_conc**2 / hole_conc,\n        )\n    elif hole_conc == 0:\n        return (\n            \"hole_conc\",\n            intrinsic_conc**2 / electron_conc,\n        )","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/electronics/carrier_concentration.py#L26-L62","documentation":"Thrown by carrier_concentration() in electronics/carrier_concentration.py when the number of zeros among (electron_conc, hole_conc, intrinsic_conc) is not exactly 1. The function solves the mass-action law n*p = ni^2 for the single unknown, which the caller signals by passing 0 for that argument; supplying zero for none or for more than one argument is ambiguous.","triggerScenarios":"carrier_concentration(electron_conc=0, hole_conc=0, intrinsic_conc=1200) (two zeros), or carrier_concentration(electron_conc=100, hole_conc=200, intrinsic_conc=1200) (no zero). Note that 0 here means 'unknown', not a physical zero.","commonSituations":"Assuming 0 is a legitimate physical concentration (doped semiconductor with no holes); migrating from an API where all three arguments were required and computed; passing None-coalesced defaults of 0.","solutions":["Pass exactly one argument as 0 — the one you want the function to compute — and real positive values for the other two.","If you genuinely meant a physical zero concentration, this API cannot model it; compute the mass-action result yourself instead.","Double-check argument order/keywords; positional mix-ups frequently leave all three non-zero."],"exampleFix":"# before\ncarrier_concentration(electron_conc=100, hole_conc=200, intrinsic_conc=1200)  # no unknown\n\n# after\ncarrier_concentration(electron_conc=0, hole_conc=200, intrinsic_conc=1200)\n# -> ('electron_conc', 7200.0)","handlingStrategy":"validation","validationCode":"args = (electron_conc, hole_conc, intrinsic_conc)\nif args.count(0) != 1:\n    raise ValueError(\"pass exactly one 0 as the unknown\")\nname, value = carrier_concentration(*args)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Remember the package-wide convention: 0 marks the argument to solve for.","Call with keyword arguments to make the unknown explicit.","Wrap the API in your own function with an explicit solve_for parameter."],"tags":["electronics","semiconductor","physics","validation","python"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}