TheAlgorithms/Python · error · TypeError

Input value of [number={number}] must be an integer

Error message

Input value of [number={number}] must be an integer

What it means

Raised by is_pronic(number) in maths/special_numbers/pronic_number.py when the argument is not an int. The function checks whether number equals k*(k+1) using an integer square root; floats (including 6.0) are rejected by the strict isinstance check even when mathematically integral.

Source

Thrown at maths/special_numbers/pronic_number.py:45

    True
    >>> is_pronic(8)
    False
    >>> is_pronic(30)
    True
    >>> is_pronic(32)
    False
    >>> is_pronic(2147441940)
    True
    >>> is_pronic(9223372033963249500)
    True
    >>> is_pronic(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 < 0 or number % 2 == 1:
        return False
    number_sqrt = int(number**0.5)
    return number == number_sqrt * (number_sqrt + 1)


if __name__ == "__main__":
    import doctest

    doctest.testmod()

View on GitHub (pinned to f5988cc097)

Solutions

  1. Coerce integral floats first: is_pronic(int(x)) when x is integral
  2. Type your data pipeline so pronic candidates stay ints (avoid float division/normalization)
  3. Guard at your boundary with isinstance(n, int) and reject early

Example fix

// before
is_pronic(6.0)  # TypeError

// after
is_pronic(int(6.0))  # True
Defensive patterns

Strategy: type-guard

Validate before calling

if not isinstance(n, int) or isinstance(n, bool):
    n = int(n)
print(is_pronic(n))

Type guard

def is_builtin_int(v) -> TypeGuard[int]:
    return isinstance(v, int) and not isinstance(v, bool)

Try / catch

try:
    is_pronic(n)
except TypeError:
    n = int(n)
    is_pronic(n)

Prevention

When it happens

Trigger: Calling is_pronic(6.0), is_pronic('12'), or is_pronic(None). Large builtin ints (e.g. 9223372033963249500) are supported and return True; only the type, not size, is checked here.

Common situations: Values coming from float arithmetic or JSON deserialization; numpy scalar types failing isinstance(x, int) in some versions.

Related errors


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