{"record":{"id":"eae16f9f70611435","repo":"TheAlgorithms/Python","slug":"exactly-one-argument-must-be-0-eae16f","errorCode":null,"errorMessage":"Exactly one argument must be 0","messagePattern":"Exactly one argument must be 0","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"electronics/electric_power.py","lineNumber":41,"sourceCode":"    >>> electric_power(voltage=2, current=4, power=2)\n    Traceback (most recent call last):\n        ...\n    ValueError: Exactly one argument must be 0\n    >>> electric_power(voltage=0, current=0, power=2)\n    Traceback (most recent call last):\n        ...\n    ValueError: Exactly one argument must be 0\n    >>> electric_power(voltage=0, current=2, power=-4)\n    Traceback (most recent call last):\n        ...\n    ValueError: Power cannot be negative in any electrical/electronics system\n    >>> electric_power(voltage=2.2, current=2.2, power=0)\n    Result(name='power', value=4.84)\n    >>> electric_power(current=0, power=6, voltage=2)\n    Result(name='current', value=3.0)\n    \"\"\"\n    if (voltage, current, power).count(0) != 1:\n        raise ValueError(\"Exactly one argument must be 0\")\n    elif power < 0:\n        raise ValueError(\n            \"Power cannot be negative in any electrical/electronics system\"\n        )\n    elif voltage == 0:\n        return Result(\"voltage\", power / current)\n    elif current == 0:\n        return Result(\"current\", power / voltage)\n    elif power == 0:\n        return Result(\"power\", float(round(abs(voltage * current), 2)))\n    else:\n        raise AssertionError\n\n\nif __name__ == \"__main__\":\n    import doctest\n\n    doctest.testmod()","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/electronics/electric_power.py#L23-L59","documentation":"Thrown by electric_power() in electronics/electric_power.py when the number of zeros among (voltage, current, power) is not exactly 1. The function solves P = V*I for the single unknown, signaled by passing 0 for that argument; zero for none or for two arguments is ambiguous and rejected. Returns a Result(name, value) namedtuple.","triggerScenarios":"electric_power(voltage=2.2, current=2.2, power=4.84) (no zero — all supplied) or electric_power(voltage=0, current=0, power=6) (two zeros). Contrast: electric_power(voltage=2.2, current=2.2, power=0) works and returns Result(name='power', value=4.84).","commonSituations":"New callers assuming a 3-required-argument API; treating 0W as a physical 'no power' query instead of the 'solve for power' marker; config systems defaulting unset fields to 0.","solutions":["Pass exactly one argument as 0 — the quantity to compute — and non-zero values for the other two.","Remember power is computed as abs(voltage * current); the API does not encode load direction.","Use keyword arguments so the unknown is obvious at the call site."],"exampleFix":"# before\nelectric_power(voltage=2.2, current=2.2, power=4.84)  # all supplied\n\n# after\nelectric_power(voltage=2.2, current=2.2, power=0)  # -> Result(name='power', value=4.84)","handlingStrategy":"validation","validationCode":"args = (voltage, current, power)\nif args.count(0) != 1:\n    raise ValueError(\"pass exactly one 0 as the unknown\")\nresult = electric_power(*args)  # Result(name='power'|'voltage'|'current', value=...)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["0 is the 'solve for me' marker, not a physical zero — do not default-fill it.","Unpack via result.name / result.value (Result namedtuple).","Power is returned as abs(voltage*current); direction must be tracked elsewhere."],"tags":["electronics","power","physics","validation","solver-api"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}