{"record":{"id":"e33f916763841fd4","repo":"TheAlgorithms/Python","slug":"input-must-be-positive","errorCode":null,"errorMessage":"Input must be positive","messagePattern":"Input must be positive","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"maths/aliquot_sum.py","lineNumber":39,"sourceCode":"    >>> aliquot_sum(0)\n    Traceback (most recent call last):\n      ...\n    ValueError: Input must be positive\n    >>> aliquot_sum(1.6)\n    Traceback (most recent call last):\n      ...\n    ValueError: Input must be an integer\n    >>> aliquot_sum(12)\n    16\n    >>> aliquot_sum(1)\n    0\n    >>> aliquot_sum(19)\n    1\n    \"\"\"\n    if not isinstance(input_num, int):\n        raise ValueError(\"Input must be an integer\")\n    if input_num <= 0:\n        raise ValueError(\"Input must be positive\")\n    return sum(\n        divisor for divisor in range(1, input_num // 2 + 1) if input_num % divisor == 0\n    )\n\n\nif __name__ == \"__main__\":\n    import doctest\n\n    doctest.testmod()\n","sourceCodeStart":21,"sourceCodeEnd":49,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/maths/aliquot_sum.py#L21-L49","documentation":"Raised by aliquot_sum when input_num is an integer but is zero or negative. Proper divisors are only defined for positive integers (the divisor range 1..n//2 is empty or meaningless otherwise), so the function rejects anything <= 0 after the type check.","triggerScenarios":"Calling aliquot_sum(0), aliquot_sum(-12), or with a computed value that underflowed to 0. bool False reaches here as 0 and True as 1 because bools pass the isinstance(int) check.","commonSituations":"Boundary values in loops over ranges that start at 0, parsed input of 0 or negatives not validated earlier, or off-by-one errors in range bounds.","solutions":["Validate n >= 1 before calling; raise or skip for non-positive inputs.","Fix loop bounds that include 0 when iterating candidate numbers.","If negatives must be handled, define your own behavior (e.g. use abs) in a wrapper - the library will not."],"exampleFix":"# before\nfor n in range(0, limit):\n    results.append(aliquot_sum(n))\n\n# after\nresults = [aliquot_sum(n) for n in range(1, limit)]","handlingStrategy":"validation","validationCode":"if n < 1:\n    raise ValueError(f'n must be >= 1, got {n}')\nresult = aliquot_sum(n)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Start candidate loops at 1, not 0.","Validate parsed numeric input against domain bounds before use."],"tags":["math","number-theory","input-validation"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}