{"record":{"id":"d1436c1eb5c6e0d1","repo":"TheAlgorithms/Python","slug":"num-cuts-must-be-a-positive-numeric-value","errorCode":null,"errorMessage":"num_cuts must be a positive numeric value.","messagePattern":"num_cuts must be a positive numeric value\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"geometry/geometry.py","lineNumber":166,"sourceCode":"        >>> circle.max_parts(0)\n        1.0\n        >>> circle.max_parts(7)\n        29.0\n        >>> circle.max_parts(54)\n        1486.0\n        >>> circle.max_parts(22.5)\n        265.375\n        >>> circle.max_parts(-222)\n        Traceback (most recent call last):\n            ...\n        TypeError: num_cuts must be a positive numeric value.\n        >>> circle.max_parts(\"-222\")\n        Traceback (most recent call last):\n            ...\n        TypeError: num_cuts must be a positive numeric value.\n        \"\"\"\n        if not isinstance(num_cuts, (int, float)) or num_cuts < 0:\n            raise TypeError(\"num_cuts must be a positive numeric value.\")\n        return (num_cuts + 2 + num_cuts**2) * 0.5\n\n\n@dataclass\nclass Polygon:\n    \"\"\"\n    An abstract class which represents Polygon on a 2D surface.\n\n    >>> Polygon()\n    Polygon(sides=[])\n    >>> polygon = Polygon()\n    >>> polygon.add_side(Side(5)).get_side(0)\n    Side(length=5, angle=Angle(degrees=90), next_side=None)\n    >>> polygon.get_side(1)\n    Traceback (most recent call last):\n        ...\n    IndexError: list index out of range\n    >>> polygon.set_side(0, Side(10)).get_side(0)","sourceCodeStart":148,"sourceCodeEnd":184,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/geometry/geometry.py#L148-L184","documentation":"Raised by Circle.max_parts (geometry/geometry.py:166) when num_cuts is not an int/float or is negative. The method computes the maximum number of pieces a circle can be divided into with num_cuts straight cuts, which is only defined for non-negative numeric cut counts.","triggerScenarios":"circle.max_parts(-222), circle.max_parts(\"-222\"), or any string/None/list argument. Note the boundary: max_parts(0) is allowed (returns 1); only values < 0 or non-numeric types raise, despite the message saying 'positive'.","commonSituations":"Feeding user input or CLI args (always strings) directly without int()/float() conversion; looping over values that can go negative due to an off-by-one; passing Decimal or numpy types not covered by isinstance(x, (int, float)) in some configurations.","solutions":["Convert string input before calling: circle.max_parts(int(user_input))","Clamp or reject negative values in your own layer: n = max(0, n)","Add isinstance/negative checks at your data boundary so bad values never reach the library"],"exampleFix":"# before\ncount = circle.max_parts(raw_cuts)  # raw_cuts may be \"-5\" or -5\n\n# after\nraw_cuts = int(raw_cuts)\nif raw_cuts < 0:\n    raise ValueError(\"cuts must be >= 0\")\ncount = circle.max_parts(raw_cuts)","handlingStrategy":"validation","validationCode":"if not isinstance(num_cuts, (int, float)) or isinstance(num_cuts, bool):\n    raise TypeError(\"num_cuts must be numeric\")\nif num_cuts < 0:\n    raise ValueError(\"num_cuts must be >= 0\")\nresult = circle.max_parts(num_cuts)","typeGuard":null,"tryCatchPattern":"try:\n    parts = circle.max_parts(n)\nexcept TypeError:\n    parts = None  # invalid input; log and skip","preventionTips":["Convert CLI/user input with int() or float() before calling","Reject negative counts at your input boundary"],"tags":["geometry","input-validation","user-input"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}