{"record":{"id":"fe6a566ab6b043ac","repo":"TheAlgorithms/Python","slug":"surface-area-conical-frustum-only-accepts-non-ne","errorCode":null,"errorMessage":"surface_area_conical_frustum() only accepts non-negative values","messagePattern":"surface_area_conical_frustum\\(\\) only accepts non-negative values","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"maths/area.py","lineNumber":166,"sourceCode":"    >>> surface_area_conical_frustum(0, 0, 0)\r\n    0.0\r\n    >>> surface_area_conical_frustum(1.6, 2.6, 3.6)\r\n    78.57907060751548\r\n    >>> surface_area_conical_frustum(-1, 2, 3)\r\n    Traceback (most recent call last):\r\n        ...\r\n    ValueError: surface_area_conical_frustum() only accepts non-negative values\r\n    >>> surface_area_conical_frustum(1, -2, 3)\r\n    Traceback (most recent call last):\r\n        ...\r\n    ValueError: surface_area_conical_frustum() only accepts non-negative values\r\n    >>> surface_area_conical_frustum(1, 2, -3)\r\n    Traceback (most recent call last):\r\n        ...\r\n    ValueError: surface_area_conical_frustum() only accepts non-negative values\r\n    \"\"\"\r\n    if radius_1 < 0 or radius_2 < 0 or height < 0:\r\n        raise ValueError(\r\n            \"surface_area_conical_frustum() only accepts non-negative values\"\r\n        )\r\n    slant_height = (height**2 + (radius_1 - radius_2) ** 2) ** 0.5\r\n    return pi * ((slant_height * (radius_1 + radius_2)) + radius_1**2 + radius_2**2)\r\n\r\n\r\ndef surface_area_cylinder(radius: float, height: float) -> float:\r\n    \"\"\"\r\n    Calculate the Surface Area of a Cylinder.\r\n    Wikipedia reference: https://en.wikipedia.org/wiki/Cylinder\r\n    Formula: 2 * pi * r * (h + r)\r\n\r\n    >>> surface_area_cylinder(7, 10)\r\n    747.6990515543707\r\n    >>> surface_area_cylinder(1.6, 2.6)\r\n    42.22300526424682\r\n    >>> surface_area_cylinder(0, 0)\r\n    0.0\r","sourceCodeStart":148,"sourceCodeEnd":184,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/maths/area.py#L148-L184","documentation":"surface_area_conical_frustum() raises this ValueError when radius_1, radius_2, or height is negative. All three are physical dimensions; the library validates them before computing the frustum surface via slant height sqrt(h^2 + (r1 - r2)^2). Note that r1 < r2 is allowed (the difference is squared), only negativity is rejected.","triggerScenarios":"Calling surface_area_conical_frustum(radius_1, radius_2, height) with any argument < 0, e.g. (-1, 2, 3), (1, -2, 3), or (1, 2, -3). Swapping argument order never triggers it by itself — only negative values do.","commonSituations":"Radii taken from an ordered list where an entry is a negative placeholder; heights derived from level differences (bottom - top); migrating from a hand-written formula that had no guards.","solutions":["Check all three arguments with min(radius_1, radius_2, height) >= 0 before the call.","Fix the upstream source of the negative dimension (data entry, subtraction direction).","Treat the radii as magnitudes: pass abs() only if sign is meaningless in your data model.","Catch ValueError and report which dimension was invalid."],"exampleFix":"// before\narea = surface_area_conical_frustum(r1, r2, h)\n\n# after\nif r1 < 0 or r2 < 0 or h < 0:\n    raise ValueError(f'frustum dimensions must be >= 0: r1={r1}, r2={r2}, h={h}')\narea = surface_area_conical_frustum(r1, r2, h)","handlingStrategy":"validation","validationCode":"if radius_1 < 0 or radius_2 < 0 or height < 0:\n    raise ValueError(f'frustum dimensions must be >= 0: {radius_1}, {radius_2}, {height}')\narea = surface_area_conical_frustum(radius_1, radius_2, height)","typeGuard":"def is_valid_frustum(r1: float, r2: float, h: float) -> bool:\n    return min(r1, r2, h) >= 0","tryCatchPattern":"try:\n    area = surface_area_conical_frustum(r1, r2, h)\nexcept ValueError as e:\n    raise ValueError(f'frustum input rejected: {e}') from e","preventionTips":["Radii order does not matter for validity — only sign; still name them explicitly.","Clean dimension columns before batch geometry processing."],"tags":["python","math","geometry","validation","valueerror","input-validation"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}