{"record":{"id":"44e9228182457d76","repo":"TheAlgorithms/Python","slug":"vol-right-circ-cone-only-accepts-non-negative-va","errorCode":null,"errorMessage":"vol_right_circ_cone() only accepts non-negative values","messagePattern":"vol_right_circ_cone\\(\\) only accepts non-negative values","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"maths/volume.py","lineNumber":257,"sourceCode":"    :return: :math:`\\frac{1}{3} \\cdot \\pi \\cdot radius^2 \\cdot height`\n\n    >>> vol_right_circ_cone(2, 3)\n    12.566370614359172\n    >>> vol_right_circ_cone(0, 0)\n    0.0\n    >>> vol_right_circ_cone(1.6, 1.6)\n    4.289321169701265\n    >>> vol_right_circ_cone(-1, 1)\n    Traceback (most recent call last):\n        ...\n    ValueError: vol_right_circ_cone() only accepts non-negative values\n    >>> vol_right_circ_cone(1, -1)\n    Traceback (most recent call last):\n        ...\n    ValueError: vol_right_circ_cone() only accepts non-negative values\n    \"\"\"\n    if height < 0 or radius < 0:\n        raise ValueError(\"vol_right_circ_cone() only accepts non-negative values\")\n    return pi * pow(radius, 2) * height / 3.0\n\n\ndef vol_prism(area_of_base: float, height: float) -> float:\n    r\"\"\"\n    | Calculate the Volume of a Prism.\n    | Wikipedia reference: https://en.wikipedia.org/wiki/Prism_(geometry)\n\n    :return: :math:`V = B \\cdot h`\n\n    >>> vol_prism(10, 2)\n    20.0\n    >>> vol_prism(11, 1)\n    11.0\n    >>> vol_prism(1.6, 1.6)\n    2.5600000000000005\n    >>> vol_prism(0, 0)\n    0.0","sourceCodeStart":239,"sourceCodeEnd":275,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/maths/volume.py#L239-L275","documentation":"Raised by vol_right_circ_cone(radius, height) in maths/volume.py when height or radius is negative. The function computes pi * radius**2 * height / 3.0 and guards both inputs; zero radius or height is fine and returns 0.0.","triggerScenarios":"Calling vol_right_circ_cone(-1, 1) or vol_right_circ_cone(1, -1); radii parsed from strings like '-2.5' or heights from inverted coordinate deltas.","commonSituations":"User-supplied dimensions in a CLI or web form containing a stray minus; measurement pipelines where a sensor sign convention produces negatives; reusing a signed 'drill depth' variable as height.","solutions":["Clamp or reject negative radius/height at input parsing (float(value) then check >= 0).","If the negative comes from an orientation convention, apply abs() or negate explicitly at the source.","Catch ValueError around the call to produce a user-facing message when input comes from end users."],"exampleFix":"# before\nvol = vol_right_circ_cone(float(raw_radius), h)\n\n# after\nr = float(raw_radius)\nif r < 0 or h < 0:\n    raise ValueError(f'dimensions must be non-negative: r={r}, h={h}')\nvol = vol_right_circ_cone(r, h)","handlingStrategy":"validation","validationCode":"if radius < 0 or height < 0:\n    raise ValueError(f'right circular cone needs non-negative r/h: {radius}, {height}')\nvol = vol_right_circ_cone(radius, height)","typeGuard":null,"tryCatchPattern":"try:\n    vol = vol_right_circ_cone(r, h)\nexcept ValueError:\n    # input came from a user form: report instead of crashing\n    return error_response('radius and height must be non-negative')","preventionTips":["Validate form/CLI numeric fields for sign before use.","Apply abs() where sign is an orientation artifact."],"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"}