{"record":{"id":"fe9958bd556bd1f2","repo":"TheAlgorithms/Python","slug":"input-value-of-number-number-must-be-an-intege-fe9958","errorCode":null,"errorMessage":"Input value of [number={number}] must be an integer","messagePattern":"Input value of \\[number=(.+?)\\] must be an integer","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"maths/special_numbers/automorphic_number.py","lineNumber":44,"sourceCode":"    True\n    >>> is_automorphic_number(7)\n    False\n    >>> is_automorphic_number(25)\n    True\n    >>> is_automorphic_number(259918212890625)\n    True\n    >>> is_automorphic_number(259918212890636)\n    False\n    >>> is_automorphic_number(740081787109376)\n    True\n    >>> is_automorphic_number(5.0)\n    Traceback (most recent call last):\n        ...\n    TypeError: Input value of [number=5.0] must be an integer\n    \"\"\"\n    if not isinstance(number, int):\n        msg = f\"Input value of [number={number}] must be an integer\"\n        raise TypeError(msg)\n    if number < 0:\n        return False\n    number_square = number * number\n    while number > 0:\n        if number % 10 != number_square % 10:\n            return False\n        number //= 10\n        number_square //= 10\n    return True\n\n\nif __name__ == \"__main__\":\n    import doctest\n\n    doctest.testmod()\n","sourceCodeStart":26,"sourceCodeEnd":60,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/maths/special_numbers/automorphic_number.py#L26-L60","documentation":"Raised by is_automorphic_number() in maths/special_numbers/automorphic_number.py when number is not an int. An automorphic number's square ends in the number itself (e.g. 76^2 = 5776), and the digit-by-digit modulo comparison requires integer arithmetic, so floats — even whole ones like 5.0 — are rejected with TypeError rather than coerced.","triggerScenarios":"Calling is_automorphic_number(5.0), is_automorphic_number('25'), or passing a bool (note: isinstance(True, int) is True in Python, so booleans are silently accepted). Division results like n/2 in Python 3 are floats and raise.","commonSituations":"Values flowing from JSON where integers were serialized as floats; results of division instead of floor division; string input not converted. Negative integers do NOT raise — they return False.","solutions":["Convert whole floats/strings explicitly: is_automorphic_number(int(x)) when x.is_integer()","Use floor division // instead of / when computing the argument","Validate types at the data boundary (API/CLI) before processing"],"exampleFix":"# before\nis_automorphic_number(value / 2)  # float -> TypeError\n\n# after\nis_automorphic_number(value // 2)  # int","handlingStrategy":"type-guard","validationCode":"if isinstance(number, float) and number.is_integer():\n    number = int(number)\nif isinstance(number, int):\n    print(is_automorphic_number(number))","typeGuard":"def is_int_number(value: object) -> bool:\n    return isinstance(value, int) and not isinstance(value, bool)","tryCatchPattern":"try:\n    is_automorphic_number(number)\nexcept TypeError as e:\n    if 'must be an integer' in str(e):\n        number = int(number)","preventionTips":["Use // not / when computing the argument","Validate numeric types at API/CLI boundaries","Booleans sneak past isinstance checks in Python — exclude them explicitly"],"tags":["python","math","number-theory","type-error"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}