{"record":{"id":"f237c5ac5b69ae13","repo":"TheAlgorithms/Python","slug":"input-is-invalid","errorCode":null,"errorMessage":"Input is invalid","messagePattern":"Input is invalid","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"info","filePath":"electronics/resistor_color_code.py","lineNumber":368,"sourceCode":"        if number_of_bands != 6:\n            temperature_coeffecient_color = None\n        else:\n            temperature_coeffecient_color = color_code_list[\n                number_of_significant_bands + 2\n            ]\n        temperature_coeffecient = (\n            0\n            if temperature_coeffecient_color is None\n            else get_temperature_coeffecient(str(temperature_coeffecient_color))\n        )\n        resisitance = significant_digits * multiplier\n        if temperature_coeffecient == 0:\n            answer = f\"{resisitance}Ω ±{tolerance}% \"\n        else:\n            answer = f\"{resisitance}Ω ±{tolerance}% {temperature_coeffecient} ppm/K\"\n        return {\"resistance\": answer}\n    else:\n        raise ValueError(\"Input is invalid\")\n\n\nif __name__ == \"__main__\":\n    import doctest\n\n    doctest.testmod()\n","sourceCodeStart":350,"sourceCodeEnd":375,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/electronics/resistor_color_code.py#L350-L375","documentation":"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.","triggerScenarios":"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.","commonSituations":"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).","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."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"ok = check_validity(number_of_bands, color_code_list)  # raises the specific error first\nresult = calculate_resistance(number_of_bands, color_code_list)","typeGuard":null,"tryCatchPattern":"try:\n    result = calculate_resistance(number_of_bands, color_code_list)\nexcept ValueError as exc:\n    # read the message: specific causes come from check_validity, not this branch\n    handle_invalid_input(str(exc))","preventionTips":["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."],"tags":["electronics","resistor","dead-code","valueerror"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}