{"record":{"id":"c54091995d505bf8","repo":"TheAlgorithms/Python","slug":"one-and-only-one-argument-must-be-0","errorCode":null,"errorMessage":"One and only one argument must be 0","messagePattern":"One and only one argument must be 0","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"electronics/coulombs_law.py","lineNumber":64,"sourceCode":"    >>> couloumbs_law(force=10, charge1=0, charge2=5, distance=2000)\n    {'charge1': 0.0008900756564307966}\n\n    >>> couloumbs_law(force=0, charge1=0, charge2=5, distance=2000)\n    Traceback (most recent call last):\n      ...\n    ValueError: One and only one argument must be 0\n\n    >>> couloumbs_law(force=0, charge1=3, charge2=5, distance=-2000)\n    Traceback (most recent call last):\n      ...\n    ValueError: Distance cannot be negative\n\n    \"\"\"\n\n    charge_product = abs(charge1 * charge2)\n\n    if (force, charge1, charge2, distance).count(0) != 1:\n        raise ValueError(\"One and only one argument must be 0\")\n    if distance < 0:\n        raise ValueError(\"Distance cannot be negative\")\n    if force == 0:\n        force = COULOMBS_CONSTANT * charge_product / (distance**2)\n        return {\"force\": force}\n    elif charge1 == 0:\n        charge1 = abs(force) * (distance**2) / (COULOMBS_CONSTANT * charge2)\n        return {\"charge1\": charge1}\n    elif charge2 == 0:\n        charge2 = abs(force) * (distance**2) / (COULOMBS_CONSTANT * charge1)\n        return {\"charge2\": charge2}\n    elif distance == 0:\n        distance = (COULOMBS_CONSTANT * charge_product / abs(force)) ** 0.5\n        return {\"distance\": distance}\n    raise ValueError(\"Exactly one argument must be 0\")\n\n\nif __name__ == \"__main__\":","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/electronics/coulombs_law.py#L46-L82","documentation":"Thrown by couloumbs_law() in electronics/coulombs_law.py when the number of zeros among (force, charge1, charge2, distance) is not exactly 1. The function solves Coulomb's law F = k*q1*q2/r^2 for whichever argument is passed as 0 ('unknown'); zero for none or more than one argument leaves the system under- or over-determined.","triggerScenarios":"couloumbs_law(force=0, charge1=0, charge2=5, distance=2000) (two zeros), or a call where all four arguments are non-zero. 0 means 'solve for me', not a physical value.","commonSituations":"Treating 0 as a physical zero force/charge; passing all measured values and expecting a consistency check; argument mix-ups when calling positionally.","solutions":["Pass exactly one argument as 0 — the quantity to compute — and non-zero values for the other three.","Note the function name is misspelled 'couloumbs_law'; make sure you are calling that exact symbol.","Use keyword arguments to make the 'unknown' explicit and self-documenting."],"exampleFix":"# before\ncouloumbs_law(force=10, charge1=3, charge2=5, distance=2000)  # no unknown\n\n# after\nforce = couloumbs_law(force=0, charge1=3, charge2=5, distance=2000)['force']","handlingStrategy":"validation","validationCode":"args = (force, charge1, charge2, distance)\nif args.count(0) != 1:\n    raise ValueError(\"pass exactly one 0 as the unknown\")\nresult = couloumbs_law(*args)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["The symbol is misspelled couloumbs_law — import that exact name.","Result comes back as a one-key dict, e.g. {'force': value}.","Use keywords so the solved-for variable is explicit."],"tags":["electronics","electrostatics","physics","validation","solver-api"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}