{"record":{"id":"bc35191d11fdbc60","repo":"TheAlgorithms/Python","slug":"you-cannot-supply-more-or-less-than-2-values-bc3519","errorCode":null,"errorMessage":"You cannot supply more or less than 2 values","messagePattern":"You cannot supply more or less than 2 values","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"physics/shear_stress.py","lineNumber":32,"sourceCode":"    tangential_force: float,\n    area: float,\n) -> tuple[str, float]:\n    \"\"\"\n    This function can calculate any one of the three -\n    1. Shear Stress\n    2. Tangential Force\n    3. Cross-sectional Area\n    This is calculated from the other two provided values\n    Examples -\n    >>> shear_stress(stress=25, tangential_force=100, area=0)\n    ('area', 4.0)\n    >>> shear_stress(stress=0, tangential_force=1600, area=200)\n    ('stress', 8.0)\n    >>> shear_stress(stress=1000, tangential_force=0, area=1200)\n    ('tangential_force', 1200000)\n    \"\"\"\n    if (stress, tangential_force, area).count(0) != 1:\n        raise ValueError(\"You cannot supply more or less than 2 values\")\n    elif stress < 0:\n        raise ValueError(\"Stress cannot be negative\")\n    elif tangential_force < 0:\n        raise ValueError(\"Tangential Force cannot be negative\")\n    elif area < 0:\n        raise ValueError(\"Area cannot be negative\")\n    elif stress == 0:\n        return (\n            \"stress\",\n            tangential_force / area,\n        )\n    elif tangential_force == 0:\n        return (\n            \"tangential_force\",\n            stress * area,\n        )\n    else:\n        return (","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/physics/shear_stress.py#L14-L50","documentation":"Raised by shear_stress(stress, tangential_force, area) in physics/shear_stress.py when the number of arguments equal to 0 among the three is not exactly one. Like gravitational_law, it is a solver: you supply two known values and 0 as the placeholder for the unknown (stress = F/A family), and it returns a (name, value) tuple.","triggerScenarios":"shear_stress(stress=25, tangential_force=100, area=50) — no zero, nothing to solve; shear_stress(stress=0, tangential_force=0, area=200) — two zeros; shear_stress(stress=0, tangential_force=0, area=0).","commonSituations":"Expecting a plain calculator (pass all three knowns) instead of a solver; UIs mapping multiple empty fields to 0; porting code that used None as the unknown sentinel.","solutions":["Pass exactly one argument as 0 for the quantity you want computed, e.g. shear_stress(stress=0, tangential_force=1600, area=200) -> ('stress', 8.0)","Unpack the returned tuple: name, value = shear_stress(...)","If validating known triples, write your own stress == tangential_force/area check instead of calling the solver"],"exampleFix":"# before\nshear_stress(stress=25, tangential_force=100, area=50)\n# ValueError: You cannot supply more or less than 2 values\n\n# after\nname, area = shear_stress(stress=25, tangential_force=100, area=0)\n# -> ('area', 4.0)","handlingStrategy":"validation","validationCode":"n = sum(v == 0 for v in (stress, tangential_force, area))\nif n != 1:\n    raise ValueError(f\"exactly one argument must be 0 (the unknown), got {n}\")\nname, value = shear_stress(stress, tangential_force, area)","typeGuard":"def has_single_zero(*vals) -> bool:\n    return sum(v == 0 for v in vals) == 1","tryCatchPattern":"try:\n    result = shear_stress(s, f, a)\nexcept ValueError as e:\n    if \"more or less than 2\" in str(e):\n        result = None  # re-ask user for exactly two knowns + one 0\n    else:\n        raise","preventionTips":["This is a solver: supply two knowns and exactly one 0 for the unknown","Unpack the (name, value) tuple return, not a bare float","Do not pass all three knowns — validate consistency yourself instead"],"tags":["physics","solver-api","argument-validation","valueerror"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}