{"record":{"id":"2d5124d582f9732d","repo":"TheAlgorithms/Python","slug":"surface-area-cone-only-accepts-non-negative-valu","errorCode":null,"errorMessage":"surface_area_cone() only accepts non-negative values","messagePattern":"surface_area_cone\\(\\) only accepts non-negative values","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"maths/area.py","lineNumber":134,"sourceCode":"    >>> surface_area_cone(1.6, 2.6)\r\n    23.387862992395807\r\n    >>> surface_area_cone(0, 0)\r\n    0.0\r\n    >>> surface_area_cone(-1, -2)\r\n    Traceback (most recent call last):\r\n        ...\r\n    ValueError: surface_area_cone() only accepts non-negative values\r\n    >>> surface_area_cone(1, -2)\r\n    Traceback (most recent call last):\r\n        ...\r\n    ValueError: surface_area_cone() only accepts non-negative values\r\n    >>> surface_area_cone(-1, 2)\r\n    Traceback (most recent call last):\r\n        ...\r\n    ValueError: surface_area_cone() only accepts non-negative values\r\n    \"\"\"\r\n    if radius < 0 or height < 0:\r\n        raise ValueError(\"surface_area_cone() only accepts non-negative values\")\r\n    return pi * radius * (radius + (height**2 + radius**2) ** 0.5)\r\n\r\n\r\ndef surface_area_conical_frustum(\r\n    radius_1: float, radius_2: float, height: float\r\n) -> float:\r\n    \"\"\"\r\n    Calculate the Surface Area of a Conical Frustum.\r\n\r\n    >>> surface_area_conical_frustum(1, 2, 3)\r\n    45.511728065337266\r\n    >>> surface_area_conical_frustum(4, 5, 6)\r\n    300.7913575056268\r\n    >>> 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","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/maths/area.py#L116-L152","documentation":"surface_area_cone() raises this ValueError when radius or height is negative. Both are physical dimensions of the cone; the library checks each before computing pi * r * (r + sqrt(h^2 + r^2)). Without the guard, a negative radius would silently return a negative area.","triggerScenarios":"Calling surface_area_cone(radius, height) with radius < 0 or height < 0, e.g. surface_area_cone(-1, 2) or surface_area_cone(1, -2). Argument order confusion (passing height where radius belongs) with signed values also triggers it.","commonSituations":"Mixing up positional arguments when refactoring to keyword style; heights computed as top - bottom with reversed coordinates; measurement imports containing negative sentinels.","solutions":["Verify both radius and height are >= 0 immediately before the call and fix whichever is negative.","If the values come from coordinates, normalize with abs(delta) before passing.","Use keyword arguments surface_area_cone(radius=..., height=...) to avoid order mistakes.","Catch ValueError to produce a domain-specific error message."],"exampleFix":"// before\narea = surface_area_cone(r, h)  # r or h may be negative deltas\n\n# after\nr, h = abs(r), abs(h)\narea = surface_area_cone(radius=r, height=h)","handlingStrategy":"validation","validationCode":"if radius < 0 or height < 0:\n    raise ValueError(f'cone dimensions must be >= 0: radius={radius}, height={height}')\narea = surface_area_cone(radius, height)","typeGuard":"def is_valid_cone_dims(radius: float, height: float) -> bool:\n    return radius >= 0 and height >= 0","tryCatchPattern":"try:\n    area = surface_area_cone(radius, height)\nexcept ValueError as e:\n    raise ValueError(f'cone input rejected ({radius=}, {height=}): {e}') from e","preventionTips":["Use keyword arguments (radius=, height=) to avoid positional mix-ups.","Normalize coordinate-derived heights with abs()."],"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"}