{"record":{"id":"f764ba3eab14b37d","repo":"TheAlgorithms/Python","slug":"input-value-of-number-number-must-be-an-intege-f764ba","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/catalan_number.py","lineNumber":35,"sourceCode":"    >>> catalan(5)\n    14\n    >>> catalan(0)\n    Traceback (most recent call last):\n        ...\n    ValueError: Input value of [number=0] must be > 0\n    >>> catalan(-1)\n    Traceback (most recent call last):\n        ...\n    ValueError: Input value of [number=-1] must be > 0\n    >>> catalan(5.0)\n    Traceback (most recent call last):\n        ...\n    TypeError: Input value of [number=5.0] must be an integer\n    \"\"\"\n\n    if not isinstance(number, int):\n        msg = f\"Input value of [number={number}] must be an integer\"\n        raise TypeError(msg)\n\n    if number < 1:\n        msg = f\"Input value of [number={number}] must be > 0\"\n        raise ValueError(msg)\n\n    current_number = 1\n\n    for i in range(1, number):\n        current_number *= 4 * i - 2\n        current_number //= i + 1\n\n    return current_number\n\n\nif __name__ == \"__main__\":\n    import doctest\n\n    doctest.testmod()","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/maths/special_numbers/catalan_number.py#L17-L53","documentation":"Raised by catalan_number() in maths/special_numbers/catalan_number.py when number is not an int. The Catalan numbers are computed with exact integer arithmetic (multiplication and floor division in a loop), so floats — even whole-valued ones like 5.0 — are rejected with TypeError. Type checking runs before the range check, so 5.0 raises this error, not the '> 0' one.","triggerScenarios":"Calling catalan_number(5.0), catalan_number('10'), or passing any non-int. Bools pass isinstance but bool True == 1 is a valid index. Division results (x/2) are the most common accidental floats.","commonSituations":"Counts derived from len()/2 style expressions; JSON/config values typed as floats; string inputs not converted. Note catalan_number(1) == 1 is the smallest valid input.","solutions":["Use floor division for computed indices: catalan_number(n // 2)","Convert at the boundary: catalan_number(int(user_value))","Coerce whole floats: int(x) if float(x).is_integer() else raise"],"exampleFix":"# before\ncatalan_number(count / 2)  # float -> TypeError\n\n# after\ncatalan_number(count // 2)  # int","handlingStrategy":"type-guard","validationCode":"number = int(number) if isinstance(number, float) and number.is_integer() else number\nprint(catalan_number(number))","typeGuard":"def is_int_number(value: object) -> bool:\n    return isinstance(value, int) and not isinstance(value, bool)","tryCatchPattern":"try:\n    catalan_number(number)\nexcept TypeError:\n    number = int(number)\n    result = catalan_number(number)","preventionTips":["Use floor division for index math","Convert JSON float counts to int","Type check runs first: 5.0 gives TypeError, 0 gives ValueError"],"tags":["python","math","combinatorics","type-error"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}