TheAlgorithms/Python · error · ValueError
is not a valid color for multiplier band
Error message
{color} is not a valid color for multiplier band What it means
Thrown by get_multiplier() in electronics/resistor_color_code.py when color is not a key of multiplier_color_values. The multiplier band accepts the ten digit colors plus Gold (0.1) and Silver (0.01), so any other name (Ivory, Aqua, ...) is rejected. Casing must match the table exactly.
Solutions
- Use a color from the multiplier table, e.g. get_multiplier('Gold') -> 0.1 or get_multiplier('Red') -> 100.0.
- Validate membership against the table keys (or a copied list of them) before calling.
- Canonicalize user input: strip whitespace, title-case, and map spelling variants to the library's names.
Example fix
# before
get_multiplier('Ivory') # ValueError
# after
get_multiplier('Gold') # 0.1
get_multiplier('Orange') # 1000.0 Defensive patterns
Strategy: type-guard
Validate before calling
MULTIPLIER_COLORS = {'Black','Brown','Red','Orange','Yellow','Green','Blue','Violet','Grey','White','Gold','Silver'}
if color not in MULTIPLIER_COLORS:
raise ValueError(f'{color!r} is not a multiplier-band color') Type guard
def is_multiplier_color(color: str) -> bool:
return color in multiplier_color_values Try / catch
try:
m = get_multiplier(color)
except ValueError as exc:
# unknown color name; fall back to prompting the user again
... Prevention
- Restrict UI input to the multiplier color set (includes Gold/Silver).
- Title-case and trim user input before passing.
- Remember Gold=0.1 and Silver=0.01 are valid multipliers here.
When it happens
Trigger: get_multiplier('Ivory'); get_multiplier('gold') if the table keys are capitalized; passing a color that is only valid for tolerance or temperature-coefficient bands.
Common situations: Free-text color input from users or a UI color picker using CSS/X11 names; sending the whole band list where the tolerance color ends up in the multiplier slot; spelling variants (Grey/Gray) not matching the table keys.
Related errors
- is not a valid color for significant figure bands
- is not a valid color for temperature coeffecient band
- is not a valid color for tolerance band
- is not a valid number of bands
- is not a valid color
AI-assisted analysis of TheAlgorithms/Python@f5988cc097 (2026-08-14).
Data as JSON: /api/errors/b23a53d84de5c76d.
Report an issue: GitHub.
Appendix: source
Thrown at electronics/resistor_color_code.py:177
def get_multiplier(color: str) -> float:
"""
Function returns the multiplier value associated with the color.
Function takes color as input and returns multiplier value
>>> get_multiplier('Gold')
0.1
>>> get_multiplier('Ivory')
Traceback (most recent call last):
...
ValueError: Ivory is not a valid color for multiplier band
"""
if color not in multiplier_color_values:
msg = f"{color} is not a valid color for multiplier band"
raise ValueError(msg)
return multiplier_color_values[color]
def get_tolerance(color: str) -> float:
"""
Function returns the tolerance value associated with the color.
Function takes color as input and returns tolerance value.
>>> get_tolerance('Green')
0.5
>>> get_tolerance('Indigo')
Traceback (most recent call last):
...
ValueError: Indigo is not a valid color for tolerance band
"""
if color not in tolerance_color_values:View on GitHub (pinned to f5988cc097)