TheAlgorithms/Python · info · ValueError
Input is invalid
Error message
Input is invalid
What it means
Raised at the trailing else of calculate_resistance() in electronics/resistor_color_code.py when check_validity() returns a falsy value. In the current code this branch is effectively dead: check_validity() either returns True or raises its own specific ValueError (invalid band count, wrong color count, unknown color), so in practice every invalid input surfaces one of those more specific messages instead. If you ever see 'Input is invalid', it means the validity contract changed (e.g. check_validity returning False) — check your installed version.
Source
Thrown at electronics/resistor_color_code.py:368
if number_of_bands != 6:
temperature_coeffecient_color = None
else:
temperature_coeffecient_color = color_code_list[
number_of_significant_bands + 2
]
temperature_coeffecient = (
0
if temperature_coeffecient_color is None
else get_temperature_coeffecient(str(temperature_coeffecient_color))
)
resisitance = significant_digits * multiplier
if temperature_coeffecient == 0:
answer = f"{resisitance}Ω ±{tolerance}% "
else:
answer = f"{resisitance}Ω ±{tolerance}% {temperature_coeffecient} ppm/K"
return {"resistance": answer}
else:
raise ValueError("Input is invalid")
if __name__ == "__main__":
import doctest
doctest.testmod()
View on GitHub (pinned to f5988cc097)
Solutions
- Don't chase this message directly — the specific cause is reported earlier by check_validity/get_band_type_count; read the full traceback.
- If you maintain a fork, make check_validity always raise with a specific message (or always return True) so this fallback stays dead.
- Verify you are importing the intended module file (check module.__file__) and clear stale bytecode.
Defensive patterns
Strategy: try-catch
Validate before calling
ok = check_validity(number_of_bands, color_code_list) # raises the specific error first result = calculate_resistance(number_of_bands, color_code_list)
Try / catch
try:
result = calculate_resistance(number_of_bands, color_code_list)
except ValueError as exc:
# read the message: specific causes come from check_validity, not this branch
handle_invalid_input(str(exc)) Prevention
- Rely on the specific messages from check_validity; treat 'Input is invalid' as a version/contract smell.
- Pin the library version in production.
- Clear stale __pycache__ after editing this module.
When it happens
Trigger: Practically unreachable with the current check_validity implementation; reachable if a modified/older version of check_validity returns None/False instead of raising, or if a subclass or monkeypatch alters its return value.
Common situations: Vendored or forked copies of the file where check_validity was changed to return False; version drift between the module you read and the one imported (stale __pycache__ or a different package on sys.path).
Related errors
- {color} is not a valid color for significant figure bands
- {color} is not a valid color for multiplier band
- {color} is not a valid color for tolerance band
- {color} is not a valid color for temperature coeffecient ban
- {total_number_of_bands} is not a valid number of bands
AI-assisted analysis of TheAlgorithms/Python@f5988cc097 (2026-08-14).
Data as JSON: /api/errors/f237c5ac5b69ae13.
Report an issue: GitHub.