{"record":{"id":"aa656ae21cff500c","repo":"TheAlgorithms/Python","slug":"color-is-not-a-valid-color-for-significant-figur","errorCode":null,"errorMessage":"{color} is not a valid color for significant figure bands","messagePattern":"(.+?) is not a valid color for significant figure bands","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"electronics/resistor_color_code.py","lineNumber":156,"sourceCode":"def get_significant_digits(colors: list) -> str:\n    \"\"\"\n    Function returns the digit associated with the color. Function takes a\n    list containing colors as input and returns digits as string\n\n    >>> get_significant_digits(['Black','Blue'])\n    '06'\n\n    >>> get_significant_digits(['Aqua','Blue'])\n    Traceback (most recent call last):\n      ...\n    ValueError: Aqua is not a valid color for significant figure bands\n\n    \"\"\"\n    digit = \"\"\n    for color in colors:\n        if color not in significant_figures_color_values:\n            msg = f\"{color} is not a valid color for significant figure bands\"\n            raise ValueError(msg)\n        digit = digit + str(significant_figures_color_values[color])\n    return str(digit)\n\n\ndef get_multiplier(color: str) -> float:\n    \"\"\"\n    Function returns the multiplier value associated with the color.\n    Function takes color as input and returns multiplier value\n\n    >>> get_multiplier('Gold')\n    0.1\n\n    >>> get_multiplier('Ivory')\n    Traceback (most recent call last):\n      ...\n    ValueError: Ivory is not a valid color for multiplier band\n\n    \"\"\"","sourceCodeStart":138,"sourceCodeEnd":174,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/electronics/resistor_color_code.py#L138-L174","documentation":"Thrown by get_significant_digits() in electronics/resistor_color_code.py when any color in the input list is not a key of significant_figures_color_values (Black, Brown, Red, Orange, Yellow, Green, Blue, Violet, Grey, White). The function concatenates the digit each color maps to; colors valid for other band types (Gold, Silver) or non-standard names (Aqua) are rejected here because significant-figure bands only use the ten digit colors.","triggerScenarios":"get_significant_digits(['Aqua','Blue']); get_significant_digits(['Gold','Black']) (Gold is multiplier/tolerance only); misspelled or lowercased names like 'blue' if the mapping is case-sensitive.","commonSituations":"Passing a full 4/5-band color list including the Gold/Silver tolerance band into the digits function; user-typed color names with different casing or spelling (Gray vs Grey); regional/HTML color names instead of the resistor standard.","solutions":["Pass only digit-band colors from the standard set: get_significant_digits(['Brown','Black']) -> '10'.","Slice off tolerance/multiplier bands before calling, e.g. colors[:2] for a 4-band resistor.","Normalize user input to the exact capitalized names used by the library's color tables."],"exampleFix":"# before\nget_significant_digits(['Aqua', 'Blue'])  # ValueError\n\n# after\nget_significant_digits(['Green', 'Blue'])  # '56'","handlingStrategy":"type-guard","validationCode":"SIGNIFICANT_COLORS = {'Black','Brown','Red','Orange','Yellow','Green','Blue','Violet','Grey','White'}\nif not all(c in SIGNIFICANT_COLORS for c in colors):\n    raise ValueError(f'invalid significant-figure color in {colors}')","typeGuard":"def are_significant_colors(colors: list[str]) -> bool:\n    return all(c in significant_figures_color_values for c in colors)","tryCatchPattern":"try:\n    digits = get_significant_digits(colors)\nexcept ValueError as exc:\n    # show the user which color was rejected: exc names it\n    ...","preventionTips":["Slice digit bands from the full color list before calling (e.g. colors[:2]).","Canonicalize casing/spelling to the library's color names.","Offer users a fixed dropdown of valid colors, not free text."],"tags":["electronics","resistor","color-code","validation","valueerror"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}