{"record":{"id":"f089b729914d9728","repo":"TheAlgorithms/Python","slug":"outer-radius-must-be-greater-than-inner-radius","errorCode":null,"errorMessage":"outer_radius must be greater than inner_radius","messagePattern":"outer_radius must be greater than inner_radius","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"maths/volume.py","lineNumber":439,"sourceCode":"    Traceback (most recent call last):\n        ...\n    ValueError: vol_hollow_circular_cylinder() only accepts non-negative values\n    >>> vol_hollow_circular_cylinder(2, 1, 3)\n    Traceback (most recent call last):\n        ...\n    ValueError: outer_radius must be greater than inner_radius\n    >>> vol_hollow_circular_cylinder(0, 0, 0)\n    Traceback (most recent call last):\n        ...\n    ValueError: outer_radius must be greater than inner_radius\n    \"\"\"\n    # Volume - (outer_radius squared - inner_radius squared) * pi * height\n    if inner_radius < 0 or outer_radius < 0 or height < 0:\n        raise ValueError(\n            \"vol_hollow_circular_cylinder() only accepts non-negative values\"\n        )\n    if outer_radius <= inner_radius:\n        raise ValueError(\"outer_radius must be greater than inner_radius\")\n    return pi * (pow(outer_radius, 2) - pow(inner_radius, 2)) * height\n\n\ndef vol_conical_frustum(height: float, radius_1: float, radius_2: float) -> float:\n    \"\"\"\n    | Calculate the Volume of a Conical Frustum.\n    | Wikipedia reference: https://en.wikipedia.org/wiki/Frustum\n\n    >>> vol_conical_frustum(45, 7, 28)\n    48490.482608158454\n    >>> vol_conical_frustum(1, 1, 2)\n    7.330382858376184\n    >>> vol_conical_frustum(1.6, 2.6, 3.6)\n    48.7240076620753\n    >>> vol_conical_frustum(0, 0, 0)\n    0.0\n    >>> vol_conical_frustum(-2, 2, 1)\n    Traceback (most recent call last):","sourceCodeStart":421,"sourceCodeEnd":457,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/maths/volume.py#L421-L457","documentation":"Raised by vol_hollow_circular_cylinder(inner_radius, outer_radius, height) in maths/volume.py when outer_radius <= inner_radius, i.e. the inner radius is not strictly smaller than the outer. A hollow cylinder requires a positive annulus, so equal radii (zero wall thickness, including the (0,0,0) case) are also rejected. It fires only after the non-negativity guard passes.","triggerScenarios":"Calling vol_hollow_circular_cylinder(2, 1, 3) (swapped arguments), vol_hollow_circular_cylinder(3, 3, 5) (equal radii), or vol_hollow_circular_cylinder(0, 0, 0); computing inner_radius = outer_radius - wall_thickness with wall_thickness == 0 or negative.","commonSituations":"Argument order confusion (passing outer first); wall thickness of 0 from a default config; inner radius derived as outer minus thickness where the thickness data equals or exceeds the outer radius.","solutions":["Pass (inner_radius, outer_radius, height) in that exact order and assert outer_radius > inner_radius > 0 before calling.","If inner_radius is derived from wall thickness, validate outer_radius - wall_thickness > 0 (and wall_thickness > 0) first.","Reject or special-case zero-thickness tubes in your data model instead of relying on the library error."],"exampleFix":"# before\nvol = vol_hollow_circular_cylinder(outer_r, inner_r, h)  # swapped -> ValueError\n\n# after\nassert 0 < inner_r < outer_r, f'need 0 < inner ({inner_r}) < outer ({outer_r})'\nvol = vol_hollow_circular_cylinder(inner_r, outer_r, h)","handlingStrategy":"validation","validationCode":"if not (0 <= inner_radius < outer_radius):\n    raise ValueError(\n        f'need inner < outer: inner={inner_radius}, outer={outer_radius}'\n    )\nvol = vol_hollow_circular_cylinder(inner_radius, outer_radius, height)","typeGuard":null,"tryCatchPattern":"try:\n    vol = vol_hollow_circular_cylinder(ir, oR, h)\nexcept ValueError as e:\n    if 'outer_radius' in str(e) and ir > oR:\n        ir, oR = oR, ir  # tolerate swapped args if that is the known bug\n        vol = vol_hollow_circular_cylinder(ir, oR, h)\n    else:\n        raise","preventionTips":["Argument order is (inner, outer, height) — inner first.","Equal radii (zero wall) are invalid; filter such records upstream.","Use keyword arguments to avoid order mistakes."],"tags":["math","validation","geometry","argument-order","valueerror"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}