{"record":{"id":"48d69453b280a466","repo":"TheAlgorithms/Python","slug":"tangential-force-cannot-be-negative","errorCode":null,"errorMessage":"Tangential Force cannot be negative","messagePattern":"Tangential Force cannot be negative","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"physics/shear_stress.py","lineNumber":36,"sourceCode":"    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 (\n            \"area\",\n            tangential_force / stress,\n        )\n","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/physics/shear_stress.py#L18-L54","documentation":"Raised by shear_stress() when tangential_force is negative (and exactly one argument is 0, with stress >= 0). Force magnitude must be non-negative in this model; the check is second in the elif chain, so it fires only when stress is not negative.","triggerScenarios":"shear_stress(stress=1000, tangential_force=-500, area=0) — negative force with area as the unknown; forces from a physics engine where direction is encoded in the sign.","commonSituations":"Signed force vectors ( opposing loads coded negative) passed as scalars; load-case tables mixing positive/negative directions; typos in hand-entered force data.","solutions":["Pass the force magnitude: shear_stress(stress=1000, tangential_force=abs(force), area=1200)","Strip directional signs from vector components before extracting the scalar magnitude","Validate force >= 0 at the data boundary in load-case pipelines"],"exampleFix":"# before\nshear_stress(stress=1000, tangential_force=-500, area=0)\n# ValueError: Tangential Force cannot be negative\n\n# after\nshear_stress(stress=1000, tangential_force=abs(-500), area=0)","handlingStrategy":"validation","validationCode":"if tangential_force < 0:\n    tangential_force = abs(tangential_force)  # if sign encoded direction only\nshear_stress(stress, tangential_force, area)","typeGuard":null,"tryCatchPattern":"try:\n    shear_stress(stress, tangential_force, area)\nexcept ValueError as e:\n    if \"Tangential Force\" in str(e):\n        shear_stress(stress, abs(tangential_force), area)\n    else:\n        raise","preventionTips":["Pass force magnitude, not a signed vector component","Strip direction from load-case tables before extracting scalar values"],"tags":["physics","validation","negative-value","valueerror"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}