{"record":{"id":"6a35cdd37110e603","repo":"TheAlgorithms/Python","slug":"input-value-must-be-a-int-type-6a35cd","errorCode":null,"errorMessage":"Input value must be a 'int' type","messagePattern":"Input value must be a 'int' type","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"bit_manipulation/binary_count_trailing_zeros.py","lineNumber":37,"sourceCode":"    >>> binary_count_trailing_zeros(0)\n    0\n    >>> binary_count_trailing_zeros(-10)\n    Traceback (most recent call last):\n        ...\n    ValueError: Input value must be a positive integer\n    >>> binary_count_trailing_zeros(0.8)\n    Traceback (most recent call last):\n        ...\n    TypeError: Input value must be a 'int' type\n    >>> binary_count_trailing_zeros(\"0\")\n    Traceback (most recent call last):\n        ...\n    TypeError: '<' not supported between instances of 'str' and 'int'\n    \"\"\"\n    if a < 0:\n        raise ValueError(\"Input value must be a positive integer\")\n    elif isinstance(a, float):\n        raise TypeError(\"Input value must be a 'int' type\")\n    return 0 if (a == 0) else int(log2(a & -a))\n\n\nif __name__ == \"__main__\":\n    import doctest\n\n    doctest.testmod()\n","sourceCodeStart":19,"sourceCodeEnd":45,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/bit_manipulation/binary_count_trailing_zeros.py#L19-L45","documentation":"Raised by binary_count_trailing_zeros when the argument is a float. The function counts trailing zero bits via log2(a & -a), which only works on integers, so non-int inputs are rejected. Note the guard runs after `a < 0`, so a non-negative float hits this TypeError while a negative float first raises a TypeError from the `<` comparison against int.","triggerScenarios":"Calling binary_count_trailing_zeros(0.8) or any non-negative float. Strings like \"0\" instead raise TypeError from `a < 0` before this line; negative floats raise ValueError('Input value must be a positive integer').","commonSituations":"Passing results of division, statistics functions, or JSON-parsed numbers that arrive as floats; forgetting to round/convert user or config input before a bit-manipulation call.","solutions":["Convert to int before calling: binary_count_trailing_zeros(int(x)) when the value is a whole-number float.","If fractional input is a bug, fix the caller to pass an integer count/index instead of a ratio or average.","Wrap the call in a type check and raise a clearer domain-specific error upstream where the value originates."],"exampleFix":"# before\nbinary_count_trailing_zeros(0.8)  # TypeError\n\n# after\nbinary_count_trailing_zeros(int(0.8))  # 0","handlingStrategy":"type-guard","validationCode":"if not isinstance(value, int) or isinstance(value, bool):\n    raise TypeError(f\"expected int, got {type(value).__name__}\")","typeGuard":"def is_int(value: object) -> bool:\n    return isinstance(value, int) and not isinstance(value, bool)","tryCatchPattern":null,"preventionTips":["Convert division/average results with int() before any bit-manipulation call.","Keep numeric data as int end-to-end; avoid round-tripping through float.","Run mypy or pyright in strict mode so float leaks into int parameters are caught statically."],"tags":["bit-manipulation","type-validation","python"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}