TheAlgorithms/Python · error · ValueError
Input value of [{number=}] must be > 0
Error message
Input value of [{number=}] must be > 0 What it means
Raised by is_proth_number(number) when the argument is a builtin int but <= 0. The algorithm subtracts 1 and repeatedly divides by 2, which is undefined for inputs < 1 (and 1 is special-cased to return False just below this guard), so non-positive integers are rejected.
Source
Thrown at maths/special_numbers/proth_number.py:93
True
>>> is_proth_number(34)
False
>>> is_proth_number(-1)
Traceback (most recent call last):
...
ValueError: Input value of [number=-1] must be > 0
>>> is_proth_number(6.0)
Traceback (most recent call last):
...
TypeError: Input value of [number=6.0] must be an integer
"""
if not isinstance(number, int):
message = f"Input value of [{number=}] must be an integer"
raise TypeError(message)
if number <= 0:
message = f"Input value of [{number=}] must be > 0"
raise ValueError(message)
if number == 1:
return False
number -= 1
n = 0
while number % 2 == 0:
n += 1
number //= 2
return number < 2**n
if __name__ == "__main__":
import doctest
doctest.testmod()
for number in range(11):View on GitHub (pinned to f5988cc097)
Solutions
- Filter candidates to >= 1 before calling (or >= 2, since 1 returns False anyway)
- Validate user-supplied candidates at your boundary
- Treat non-positive inputs as 'not a Proth number' in your own wrapper before delegating
Example fix
// before ok = is_proth_number(-1) # ValueError // after ok = is_proth_number(25)
Defensive patterns
Strategy: validation
Validate before calling
if n < 1:
ok = False # non-positives are simply not Proth numbers
else:
ok = is_proth_number(n) Prevention
- Filter candidates to >= 1 before screening
- 1 returns False without raising — only <= 0 raises
- Validate user-supplied candidate lists up front
When it happens
Trigger: Calling is_proth_number(0) or is_proth_number(-1). This fires only after the isinstance check passes; non-integers raise the TypeError above.
Common situations: Screening raw user input or sensor values that can be 0/negative without pre-filtering; iterating a range that includes 0.
Related errors
- Input value of [number={number}] must be > 0
- surface_area_cube() only accepts non-negative values
- surface_area_cuboid() only accepts non-negative values
- surface_area_sphere() only accepts non-negative values
- surface_area_hemisphere() only accepts non-negative values
AI-assisted analysis of TheAlgorithms/Python@f5988cc097 (2026-08-14).
Data as JSON: /api/errors/a1d0c757883938b4.
Report an issue: GitHub.