{"record":{"id":"a20993463ced5934","repo":"TheAlgorithms/Python","slug":"vol-hollow-circular-cylinder-only-accepts-non-ne","errorCode":null,"errorMessage":"vol_hollow_circular_cylinder() only accepts non-negative values","messagePattern":"vol_hollow_circular_cylinder\\(\\) only accepts non-negative values","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"maths/volume.py","lineNumber":435,"sourceCode":"    Traceback (most recent call last):\n        ...\n    ValueError: vol_hollow_circular_cylinder() only accepts non-negative values\n    >>> vol_hollow_circular_cylinder(1, 2, -3)\n    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","sourceCodeStart":417,"sourceCodeEnd":453,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/maths/volume.py#L417-L453","documentation":"Raised by vol_hollow_circular_cylinder(inner_radius, outer_radius, height) in maths/volume.py when inner_radius, outer_radius or height is negative. This is the first of two guards: it only checks signs; a second guard then enforces outer_radius > inner_radius. The result is pi * (outer**2 - inner**2) * height.","triggerScenarios":"Calling vol_hollow_circular_cylinder(-1, 2, 3), (1, -2, 3) or (1, 2, -3); pipe/tube parameters imported with sign errors or swapped-but-negative values.","commonSituations":"CAD or piping data where wall thickness is stored as a negative offset from the outer radius; measurement files with minus signs from a calibration offset; mixing inner/outer columns in a spreadsheet.","solutions":["Validate all three arguments are >= 0 before the call (and outer > inner to also avoid the second ValueError).","Recompute inner_radius = outer_radius - wall_thickness and clamp/validate the result when thickness data is offset-based.","Check column mapping of your import file if negatives appear systematically."],"exampleFix":"# before\nvol = vol_hollow_circular_cylinder(outer_r - wall, outer_r, h)  # negative when wall > outer_r\n\n# after\ninner_r = outer_r - wall\nif inner_r < 0:\n    raise ValueError(f'wall thickness {wall} exceeds outer radius {outer_r}')\nvol = vol_hollow_circular_cylinder(inner_r, outer_r, h)","handlingStrategy":"validation","validationCode":"if inner_radius < 0 or outer_radius < 0 or height < 0:\n    raise ValueError(f'hollow cylinder args must be >= 0: {inner_radius}, {outer_radius}, {height}')\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    raise ValueError(f'bad tube geometry ir={ir}, oR={oR}, h={h}: {e}') from e","preventionTips":["Validate wall-thickness-derived inner radii before the call.","Check import column mapping when negatives appear systematically."],"tags":["math","validation","geometry","valueerror"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}