{"record":{"id":"336927da202f73d3","repo":"TheAlgorithms/Python","slug":"input-value-of-number-number-must-be-0","errorCode":null,"errorMessage":"Input value of [number={number}] must be > 0","messagePattern":"Input value of \\[number=(.+?)\\] must be > 0","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"maths/special_numbers/catalan_number.py","lineNumber":39,"sourceCode":"        ...\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()\n","sourceCodeStart":21,"sourceCodeEnd":54,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/maths/special_numbers/catalan_number.py#L21-L54","documentation":"Raised by catalan_number() when number is an int but < 1. The first Catalan number is C(1) = 1 (this implementation's convention — it returns 1 for number=1), so 0 and negatives have no value under its iterative product formula and are rejected. The type check has already passed by this point, so this error means 'right type, out-of-range value'.","triggerScenarios":"Calling catalan_number(0) or catalan_number(-1). Typical when an index computed as a difference or a parsed default lands on 0. Note that the standard math convention C(0) = 1 is NOT supported here — callers porting formulas that use 0-based Catalan indices must shift by one.","commonSituations":"Porting code that assumes C(0)=1 and calling with 0; loop bounds starting at 0 (for i in range(0, n): catalan_number(i)); user input of 0 treated as valid.","solutions":["Shift 0-based indices to the 1-based convention this function expects: catalan_number(i + 1)","Guard the boundary: catalan_number(n) if n >= 1 else 1 (if your math needs C(0)=1)","Start loops at 1: range(1, n + 1) instead of range(n)"],"exampleFix":"# before\nfor i in range(n):\n    values.append(catalan_number(i))  # i=0 -> ValueError\n\n# after\nfor i in range(1, n + 1):\n    values.append(catalan_number(i))","handlingStrategy":"validation","validationCode":"if number >= 1:\n    c = catalan_number(number)\nelse:\n    c = 1  # if your math assumes C(0) = 1, handle it yourself","typeGuard":"def is_valid_catalan_index(value: object) -> bool:\n    return isinstance(value, int) and not isinstance(value, bool) and value >= 1","tryCatchPattern":null,"preventionTips":["This API is 1-based; shift 0-based Catalan indices by +1","Start loops at range(1, n + 1)","catalan_number(1) == 1 is the smallest supported input"],"tags":["python","math","combinatorics","off-by-one","value-error"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}