{"record":{"id":"376d5a450d3dfa28","repo":"TheAlgorithms/Python","slug":"input-value-must-be-a-positive-integer-376d5a","errorCode":null,"errorMessage":"Input value must be a positive integer","messagePattern":"Input value must be a positive integer","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"bit_manipulation/binary_count_trailing_zeros.py","lineNumber":35,"sourceCode":"    >>> binary_count_trailing_zeros(4294967296)\n    32\n    >>> 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":17,"sourceCodeEnd":45,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/bit_manipulation/binary_count_trailing_zeros.py#L17-L45","documentation":"Raised by check_args() in physics/horizontal_projectile_motion.py when the angle is outside 1-90 degrees inclusive. The projectile formulas in this module model forward launches only, so 0 (horizontal) and 90 (vertical) are excluded along with everything outside the range. This is a domain restriction, not a type problem — the value is numeric but out of range.","triggerScenarios":"horizontal_distance(50, 0); horizontal_distance(50, 95); horizontal_distance(50, -30); horizontal_distance(50, 90.5). The check is angle > 90 or angle < 1, so exactly 1 and exactly 90 are valid — 0 (purely horizontal) and anything past 90 raise.","commonSituations":"Angles computed modulo arithmetic that land at 0 or above 90; converting radians to degrees incorrectly (e.g. passing 1.57 radians directly); spherical-coordinate data where elevation can be negative or exceed 90.","solutions":["Clamp or reject out-of-range angles before calling: if not 1 <= angle <= 90, skip or rescale.","Convert radians to degrees with math.degrees() before the call.","Handle the 0-degree (purely horizontal) and 90-degree (vertical) cases with dedicated code, since this module excludes them."],"exampleFix":"# before\ndist = horizontal_distance(50, math.radians_result)  # e.g. 0.786 -> ValueError\n\n# after\nangle_deg = math.degrees(theta_rad)\nif not 1 <= angle_deg <= 90:\n    raise ValueError(f\"angle {angle_deg} outside projectile range 1-90\")\ndist = horizontal_distance(50, angle_deg)","handlingStrategy":"validation","validationCode":"if not 1 <= angle <= 90:\n    raise ValueError(f\"angle must be in [1, 90] degrees, got {angle}\")\ndist = horizontal_distance(init_velocity, angle)","typeGuard":"def is_valid_launch_angle(a: object) -> bool:\n    return isinstance(a, (int, float)) and not isinstance(a, bool) and 1 <= a <= 90","tryCatchPattern":"try:\n    dist = horizontal_distance(v, angle)\nexcept ValueError as e:\n    if \"Range is 1-90\" in str(e):\n        angle = min(max(angle, 1), 90)  # clamp only if acceptable for your use\n        dist = horizontal_distance(v, angle)\n    else:\n        raise","preventionTips":["Convert radians with math.degrees() before calling.","Both 0 and 90 degrees are rejected — handle those launch cases with dedicated code.","Angles from modulo arithmetic can land at 0; validate before the call."],"tags":["physics","domain-error","range-validation","units"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}