TheAlgorithms/Python · error · ValueError

Input value of [number={number}] must be > 0

Error message

Input value of [number={number}] must be > 0

What it means

Raised by proth(number) when the argument is an int but less than 1. The Proth sequence is 1-indexed (proth(1) == 3, proth(2) == 5, then log-based indexing for n >= 3), so 0 and negative indices are meaningless and rejected after the type check.

Source

Thrown at maths/special_numbers/proth_number.py:37

        ...
    ValueError: Input value of [number=0] must be > 0
    >>> proth(-1)
    Traceback (most recent call last):
        ...
    ValueError: Input value of [number=-1] must be > 0
    >>> proth(6.0)
    Traceback (most recent call last):
        ...
    TypeError: Input value of [number=6.0] must be an integer
    """

    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)
    elif number == 1:
        return 3
    elif number == 2:
        return 5
    else:
        """
        +1 for binary starting at 0 i.e. 2^0, 2^1, etc.
        +1 to start the sequence at the 3rd Proth number
        Hence, we have a +2 in the below statement
        """
        block_index = int(math.log(number // 3, 2)) + 2

        proth_list = [3, 5]
        proth_index = 2
        increment = 3
        for block in range(1, block_index):
            for _ in range(increment):
                proth_list.append(2 ** (block + 1) + proth_list[proth_index - 1])

View on GitHub (pinned to f5988cc097)

Solutions

  1. Shift 0-based indices by one: proth(i + 1)
  2. Loop from 1: `for i in range(1, n + 1)`
  3. Clamp or validate computed indices to >= 1 before calling

Example fix

// before
p = proth(0)  # ValueError

// after
p = proth(1)  # first Proth number, 3
Defensive patterns

Strategy: validation

Validate before calling

if n < 1:
    raise IndexError('proth is 1-indexed; got %r' % n)
p = proth(n)

Prevention

When it happens

Trigger: Calling proth(0) or proth(-1). Non-integers raise the TypeError first; this ValueError only fires for builtin ints below 1.

Common situations: 0-based loops (`range(0, n)`) feeding a 1-based sequence API; computing an index that can go to 0 or negative on degenerate input (empty list -> idx 0).

Related errors


AI-assisted analysis of TheAlgorithms/Python@f5988cc097 (2026-08-14). Data as JSON: /api/errors/dda4875ae2d33ae5. Report an issue: GitHub.