{"record":{"id":"826868a421ce5127","repo":"TheAlgorithms/Python","slug":"vol-circular-cylinder-only-accepts-non-negative","errorCode":null,"errorMessage":"vol_circular_cylinder() only accepts non-negative values","messagePattern":"vol_circular_cylinder\\(\\) only accepts non-negative values","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"maths/volume.py","lineNumber":397,"sourceCode":"    >>> vol_circular_cylinder(1, 1)\n    3.141592653589793\n    >>> vol_circular_cylinder(4, 3)\n    150.79644737231007\n    >>> vol_circular_cylinder(1.6, 1.6)\n    12.867963509103795\n    >>> vol_circular_cylinder(0, 0)\n    0.0\n    >>> vol_circular_cylinder(-1, 1)\n    Traceback (most recent call last):\n        ...\n    ValueError: vol_circular_cylinder() only accepts non-negative values\n    >>> vol_circular_cylinder(1, -1)\n    Traceback (most recent call last):\n        ...\n    ValueError: vol_circular_cylinder() only accepts non-negative values\n    \"\"\"\n    if height < 0 or radius < 0:\n        raise ValueError(\"vol_circular_cylinder() only accepts non-negative values\")\n    # Volume is radius squared * height * pi\n    return pow(radius, 2) * height * pi\n\n\ndef vol_hollow_circular_cylinder(\n    inner_radius: float, outer_radius: float, height: float\n) -> float:\n    \"\"\"\n    Calculate the Volume of a Hollow Circular Cylinder.\n\n    >>> vol_hollow_circular_cylinder(1, 2, 3)\n    28.274333882308138\n    >>> vol_hollow_circular_cylinder(1.6, 2.6, 3.6)\n    47.50088092227767\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","sourceCodeStart":379,"sourceCodeEnd":415,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/maths/volume.py#L379-L415","documentation":"Raised by vol_circular_cylinder(radius, height) in maths/volume.py when height or radius is negative. The function returns radius**2 * height * pi after validating both inputs; zero radius or height is accepted and returns 0.0.","triggerScenarios":"Calling vol_circular_cylinder(-1, 1) or vol_circular_cylinder(1, -1); heights encoded as signed depth (e.g. -10 for a borehole) passed directly.","commonSituations":"Downward measurements (drilling, excavation) stored as negative depth; CSV sign conventions differing between exports; reusing a signed delta as height.","solutions":["Convert signed depths to magnitudes with abs() before calling.","Validate radius and height >= 0 where the data enters your program.","Catch ValueError and re-raise with context (which object/record had the bad dimension) for easier debugging."],"exampleFix":"# before\nvol = vol_circular_cylinder(r, borehole_depth)  # ValueError if depth negative\n\n# after\nvol = vol_circular_cylinder(r, abs(borehole_depth))","handlingStrategy":"validation","validationCode":"if radius < 0 or height < 0:\n    raise ValueError(f'cylinder needs non-negative r/h: {radius}, {height}')\nvol = vol_circular_cylinder(radius, height)","typeGuard":null,"tryCatchPattern":"try:\n    vol = vol_circular_cylinder(r, h)\nexcept ValueError:\n    vol = vol_circular_cylinder(abs(r), abs(h))  # only if signs are artifacts","preventionTips":["Downward depths stored as negatives must be converted with abs().","Standardize a sign convention for depths across your dataset."],"tags":["math","validation","geometry","valueerror"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}