{"record":{"id":"d8b5786d499a83dc","repo":"TheAlgorithms/Python","slug":"input-value-of-number-number-must-be-an-intege-d8b578","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/liouville_lambda.py","lineNumber":37,"sourceCode":"    1\n    >>> liouville_lambda(11)\n    -1\n    >>> liouville_lambda(0)\n    Traceback (most recent call last):\n        ...\n    ValueError: Input must be a positive integer\n    >>> liouville_lambda(-1)\n    Traceback (most recent call last):\n        ...\n    ValueError: Input must be a positive integer\n    >>> liouville_lambda(11.0)\n    Traceback (most recent call last):\n        ...\n    TypeError: Input value of [number=11.0] must be an integer\n    \"\"\"\n    if not isinstance(number, int):\n        msg = f\"Input value of [number={number}] must be an integer\"\n        raise TypeError(msg)\n    if number < 1:\n        raise ValueError(\"Input must be a positive integer\")\n    return -1 if len(prime_factors(number)) % 2 else 1\n\n\nif __name__ == \"__main__\":\n    import doctest\n\n    doctest.testmod()\n","sourceCodeStart":19,"sourceCodeEnd":47,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/maths/liouville_lambda.py#L19-L47","documentation":"Raised by liouville_lambda in maths/liouville_lambda.py when number is not an int. The Liouville function lambda(n) = (-1)^k where k is the number of prime factors of n (with multiplicity), computed here via len(prime_factors(number)) % 2, which requires an exact integer to factor; non-ints are rejected with TypeError before factorization. Note 11.0 fails even though it is whole.","triggerScenarios":"Calling liouville_lambda(11.0), liouville_lambda('7'), or liouville_lambda(2+0j). The isinstance check fires first; ints >= 1 proceed to prime factorization.","commonSituations":"Number-theory pipelines where values passed through float operations lose int type; JSON/config-sourced numbers; numpy integer scalars failing isinstance(x, int).","solutions":["Convert before calling: liouville_lambda(int(number)).","If truncation would be wrong, validate integrality: assert number == int(number).","Cast numpy scalars with int() at the boundary."],"exampleFix":"// before\nlam = liouville_lambda(n)  # n is 11.0\n\n// after\nlam = liouville_lambda(int(n))","handlingStrategy":"type-guard","validationCode":"number = int(number)  # after confirming number == int(number) if truncation matters\nlam = liouville_lambda(number)","typeGuard":"def is_int_value(v) -> bool:\n    return isinstance(v, int) or (isinstance(v, float) and v.is_integer())","tryCatchPattern":"try:\n    lam = liouville_lambda(n)\nexcept TypeError:\n    lam = liouville_lambda(int(n))","preventionTips":["Cast numpy/float values to int at the boundary","Keep number-theory inputs as native ints end to end"],"tags":["math","number-theory","liouville","typeerror"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}