TheAlgorithms/Python · error · TypeError
Input value must be a 'int' type
Error message
Input value must be a 'int' type
What it means
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.
Source
Thrown at bit_manipulation/binary_count_setbits.py:34
>>> binary_count_setbits(0)
0
>>> binary_count_setbits(-10)
Traceback (most recent call last):
...
ValueError: Input value must be a positive integer
>>> binary_count_setbits(0.8)
Traceback (most recent call last):
...
TypeError: Input value must be a 'int' type
>>> binary_count_setbits("0")
Traceback (most recent call last):
...
TypeError: '<' not supported between instances of 'str' and 'int'
"""
if a < 0:
raise ValueError("Input value must be a positive integer")
elif isinstance(a, float):
raise TypeError("Input value must be a 'int' type")
return bin(a).count("1")
if __name__ == "__main__":
import doctest
doctest.testmod()
View on GitHub (pinned to f5988cc097)
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.
Example fix
# before
dist = horizontal_distance(50, angle_str) # '45deg' -> TypeError
# after
angle = float(angle_str.replace('deg', '').strip())
dist = horizontal_distance(50, angle) Defensive patterns
Strategy: type-guard
Validate before calling
if not isinstance(angle, (int, float)) or isinstance(angle, bool):
raise TypeError(f"angle must be numeric, got {type(angle).__name__}")
dist = horizontal_distance(init_velocity, angle) Type guard
def is_numeric_angle(a: object) -> bool:
return isinstance(a, (int, float)) and not isinstance(a, bool) Try / catch
try:
dist = horizontal_distance(v, angle)
except TypeError as e:
if "angle" in str(e):
dist = horizontal_distance(v, float(str(angle).strip().rstrip('deg°')))
else:
raise Prevention
- 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.
When it happens
Trigger: horizontal_distance(50, '45'); horizontal_distance(50, None); passing an angle in radians as a sympy/Decimal object, or unparsed form input like '45deg'.
Common situations: 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.
Related errors
- Input value must be a positive integer
- Expected a list of numbers as input, found {type(item).__nam
- Expected a list of numbers as input, found {type(point).__na
- Input must be an integer
- Initial orbit radius must be greater than zero.
AI-assisted analysis of TheAlgorithms/Python@f5988cc097 (2026-08-14).
Data as JSON: /api/errors/6cba003da863588f.
Report an issue: GitHub.