{"record":{"id":"fbbcb74e7918d6d0","repo":"TheAlgorithms/Python","slug":"input-value-of-number-number-must-be-an-intege-fbbcb7","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/hexagonal_number.py","lineNumber":40,"sourceCode":"    231\n    >>> hexagonal(22)\n    946\n    >>> hexagonal(0)\n    Traceback (most recent call last):\n        ...\n    ValueError: Input must be a positive integer\n    >>> hexagonal(-1)\n    Traceback (most recent call last):\n        ...\n    ValueError: Input must be a positive integer\n    >>> hexagonal(11.0)\n    Traceback (most recent call last):\n        ...\n    TypeError: Input value of [number=11.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 < 1:\n        raise ValueError(\"Input must be a positive integer\")\n    return number * (2 * number - 1)\n\n\nif __name__ == \"__main__\":\n    import doctest\n\n    doctest.testmod()\n","sourceCodeStart":22,"sourceCodeEnd":50,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/maths/special_numbers/hexagonal_number.py#L22-L50","documentation":"Raised by hexagonal(number) in maths/special_numbers/hexagonal_number.py when the argument is not an int. It computes the n-th hexagonal number with the closed formula n*(2n-1); because isinstance(number, int) is strict, floats (even integral ones like 11.0), strings, and None all fail. Note that bool passes since bool subclasses int.","triggerScenarios":"Calling hexagonal(11.0), hexagonal('5'), or hexagonal(None). Floats are rejected even when they hold an exact integer value; use of numpy integer types may also fail depending on version.","commonSituations":"Data arriving from JSON or pandas as floats (11.0 instead of 11), or from a division result; mixing numpy int64 scalars into a codebase that expects builtin ints.","solutions":["Convert integral floats before calling: hexagonal(int(x)) when float(x).is_integer()","Fix upstream data types (e.g. use dtype int columns or json int parsing) so the value is a builtin int","Add your own isinstance check at the API boundary with a clearer domain-specific message"],"exampleFix":"// before\nh = hexagonal(11.0)  # TypeError\n\n// after\nn = int(11.0)\nh = hexagonal(n)","handlingStrategy":"type-guard","validationCode":"if not isinstance(n, int) or isinstance(n, bool):\n    n = int(n)  # only after confirming integrality\nh = hexagonal(n)","typeGuard":"def is_builtin_int(v) -> TypeGuard[int]:\n    return isinstance(v, int) and not isinstance(v, bool)","tryCatchPattern":"try:\n    h = hexagonal(n)\nexcept TypeError:\n    n = int(n)\n    h = hexagonal(n)","preventionTips":["Normalize float->int at the JSON/pandas boundary","Watch out: bool passes the isinstance(int) check","Use integer division // to keep indices integral"],"tags":["math","typeerror","type-checking","hexagonal"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}