{"record":{"id":"6cba003da863588f","repo":"TheAlgorithms/Python","slug":"input-value-must-be-a-int-type","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_setbits.py","lineNumber":34,"sourceCode":"    >>> binary_count_setbits(0)\n    0\n    >>> binary_count_setbits(-10)\n    Traceback (most recent call last):\n        ...\n    ValueError: Input value must be a positive integer\n    >>> binary_count_setbits(0.8)\n    Traceback (most recent call last):\n        ...\n    TypeError: Input value must be a 'int' type\n    >>> binary_count_setbits(\"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 bin(a).count(\"1\")\n\n\nif __name__ == \"__main__\":\n    import doctest\n\n    doctest.testmod()\n","sourceCodeStart":16,"sourceCodeEnd":42,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/bit_manipulation/binary_count_setbits.py#L16-L42","documentation":"Raised by check_args() in physics/horizontal_projectile_motion.py when the angle argument is not an int or float. Same shared validator as the velocity check: it runs after the velocity type check, so a bad velocity raises first if both are wrong. Strings (e.g. '45'), None, and Decimals all trigger it.","triggerScenarios":"horizontal_distance(50, '45'); horizontal_distance(50, None); passing an angle in radians as a sympy/Decimal object, or unparsed form input like '45deg'.","commonSituations":"Angles arriving as strings with units attached ('45 degrees', '45°') from user input; None defaults for optional angle parameters; angles stored as text in CSV columns.","solutions":["Parse the angle to a plain float and strip unit suffixes before calling.","Default optional angles to a numeric value (e.g. 45.0) instead of None.","Catch TypeError and re-prompt / reject the input at the boundary."],"exampleFix":"# before\ndist = horizontal_distance(50, angle_str)  # '45deg' -> TypeError\n\n# after\nangle = float(angle_str.replace('deg', '').strip())\ndist = horizontal_distance(50, angle)","handlingStrategy":"type-guard","validationCode":"if not isinstance(angle, (int, float)) or isinstance(angle, bool):\n    raise TypeError(f\"angle must be numeric, got {type(angle).__name__}\")\ndist = horizontal_distance(init_velocity, angle)","typeGuard":"def is_numeric_angle(a: object) -> bool:\n    return isinstance(a, (int, float)) and not isinstance(a, bool)","tryCatchPattern":"try:\n    dist = horizontal_distance(v, angle)\nexcept TypeError as e:\n    if \"angle\" in str(e):\n        dist = horizontal_distance(v, float(str(angle).strip().rstrip('deg°')))\n    else:\n        raise","preventionTips":["Strip unit suffixes ('45deg', '45°') before parsing.","Default optional angles to a number, never None.","The angle type check runs after the velocity check — fix velocity first if both fail."],"tags":["physics","typeerror","type-validation","user-input"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}