calculate the nth catalan number source https en wikipedia orgwikicatalannumber param number nth catalan number to calculate return the nth catalan number note a catalan number is only defined for positive integers catalan5 14 catalan0 traceback most recent call last valueerror input value of number0 must be 0 catalan1 traceback most recent call last valueerror input value of number1 must be 0 catalan5 0 traceback most recent call last typeerror input value of number5 0 must be an integer param number nth catalan number to calculate return the nth catalan number note a catalan number is only defined for positive integers catalan 5 14 catalan 0 traceback most recent call last valueerror input value of number 0 must be 0 catalan 1 traceback most recent call last valueerror input value of number 1 must be 0 catalan 5 0 traceback most recent call last typeerror input value of number 5 0 must be an integer
def catalan(number: int) -> int:
    

    if not isinstance(number, int):
        msg = f"Input value of [number={number}] must be an integer"
        raise TypeError(msg)

    if number < 1:
        msg = f"Input value of [number={number}] must be > 0"
        raise ValueError(msg)

    current_number = 1

    for i in range(1, number):
        current_number *= 4 * i - 2
        current_number //= i + 1

    return current_number


if __name__ == "__main__":
    import doctest

    doctest.testmod()