{"record":{"id":"cfa347d79a46c192","repo":"TheAlgorithms/Python","slug":"color-is-not-a-valid-color-for-tolerance-band","errorCode":null,"errorMessage":"{color} is not a valid color for tolerance band","messagePattern":"(.+?) is not a valid color for tolerance band","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"electronics/resistor_color_code.py","lineNumber":197,"sourceCode":"\n\ndef get_tolerance(color: str) -> float:\n    \"\"\"\n    Function returns the tolerance value associated with the color.\n    Function takes color as input and returns tolerance value.\n\n    >>> get_tolerance('Green')\n    0.5\n\n    >>> get_tolerance('Indigo')\n    Traceback (most recent call last):\n      ...\n    ValueError: Indigo is not a valid color for tolerance band\n\n    \"\"\"\n    if color not in tolerance_color_values:\n        msg = f\"{color} is not a valid color for tolerance band\"\n        raise ValueError(msg)\n    return tolerance_color_values[color]\n\n\ndef get_temperature_coeffecient(color: str) -> int:\n    \"\"\"\n    Function returns the temperature coeffecient value associated with the color.\n    Function takes color as input and returns temperature coeffecient value.\n\n    >>> get_temperature_coeffecient('Yellow')\n    25\n\n    >>> get_temperature_coeffecient('Cyan')\n    Traceback (most recent call last):\n      ...\n    ValueError: Cyan is not a valid color for temperature coeffecient band\n\n    \"\"\"\n    if color not in temperature_coeffecient_color_values:","sourceCodeStart":179,"sourceCodeEnd":215,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/electronics/resistor_color_code.py#L179-L215","documentation":"Thrown by get_tolerance() in electronics/resistor_color_code.py when color is not a key of tolerance_color_values (typically Brown, Red, Green, Blue, Violet, Gold, Silver and similar per the library table). Tolerance bands use a different color set than digit or multiplier bands, so colors valid elsewhere (Indigo, Yellow for temp-coeff) are rejected here.","triggerScenarios":"get_tolerance('Indigo'); passing a digit-band-only color like 'Yellow' (if absent from the tolerance table); passing the multiplier color when the tolerance color was intended.","commonSituations":"Mixing up band positions when decoding by hand; UI dropdowns listing all colors for every band; user-entered color names with wrong casing or non-standard variants.","solutions":["Use a tolerance-band color: get_tolerance('Green') -> 0.5, get_tolerance('Gold') -> 5.0.","Confirm you are reading the correct band position (last band on a 4/5-band resistor).","Pre-validate against the library's tolerance_color_values keys and normalize casing."],"exampleFix":"# before\nget_tolerance('Indigo')  # ValueError\n\n# after\nget_tolerance('Green')  # 0.5","handlingStrategy":"type-guard","validationCode":"if color not in tolerance_color_values:\n    raise ValueError(f'{color!r} is not a tolerance-band color')","typeGuard":"def is_tolerance_color(color: str) -> bool:\n    return color in tolerance_color_values","tryCatchPattern":"try:\n    t = get_tolerance(color)\nexcept ValueError as exc:\n    # re-prompt for the correct tolerance-band color\n    ...","preventionTips":["Confirm band position: tolerance is the last band on 4/5-band resistors.","Use the library's exact color spelling (Grey vs Gray).","Give users a dropdown limited to tolerance colors."],"tags":["electronics","resistor","color-code","tolerance","valueerror"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}