{"record":{"id":"869c53a22b8a4d95","repo":"TheAlgorithms/Python","slug":"input-must-be-an-integer","errorCode":null,"errorMessage":"Input must be an integer","messagePattern":"Input must be an integer","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"maths/aliquot_sum.py","lineNumber":37,"sourceCode":"      ...\n    ValueError: Input must be positive\n    >>> 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":19,"sourceCodeEnd":49,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/maths/aliquot_sum.py#L19-L49","documentation":"Raised by aliquot_sum in maths/aliquot_sum.py when input_num is not an int (e.g. 1.6 or a string). The function sums proper divisors via the modulo operator, which is only meaningful for integers, so non-integers are rejected before the divisor scan.","triggerScenarios":"Calling aliquot_sum(1.6), aliquot_sum('12'), or with a numpy float. Note: Python bool passes this check because bool subclasses int - True is treated as 1.","commonSituations":"Values arriving from JSON parsing or user input as floats (12.0 fails too, since 12.0 is a float not an int), or unconverted string parameters from CLI args.","solutions":["Convert to int first if the value is integral: aliquot_sum(int(x)) after verifying x is whole.","Validate upstream input types before the numeric pipeline.","Reject bools explicitly if they can occur: isinstance(x, bool) check before passing."],"exampleFix":"# before\nresult = aliquot_sum(user_value)  # user_value is 12.0 from JSON\n\n# after\nif not (isinstance(user_value, int) and not isinstance(user_value, bool)):\n    user_value = int(user_value)\nresult = aliquot_sum(user_value)","handlingStrategy":"type-guard","validationCode":"if not isinstance(user_value, int) or isinstance(user_value, bool):\n    if not float(user_value).is_integer():\n        raise TypeError('value must be a whole number')\n    user_value = int(user_value)\nresult = aliquot_sum(user_value)","typeGuard":"def is_whole_int(value) -> bool:\n    return isinstance(value, int) and not isinstance(value, bool)","tryCatchPattern":null,"preventionTips":["Convert JSON/CLI inputs with int() after a whole-number check.","Remember floats like 12.0 fail the isinstance check even though integral."],"tags":["math","number-theory","type-validation"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}