diff --git a/resistor-color-expert/resistor_color_expert.py b/resistor-color-expert/resistor_color_expert.py index 0643cb4..35f7980 100644 --- a/resistor-color-expert/resistor_color_expert.py +++ b/resistor-color-expert/resistor_color_expert.py @@ -51,26 +51,15 @@ def resistor_label(colors: list[str]) -> str: :rtype: str :raises KeyError: If an unknown color is provided. """ - prefix: str = "" postfix: str = "" max_tolerance: str = "" if len(colors) == 1: - prefix: str = f"{COLOR_VALUES[colors[0]]}" - - if len(colors) == 4: - prefix: str = f"{COLOR_VALUES[colors[0]]}{COLOR_VALUES[colors[1]]}" - postfix = f"{'0' * COLOR_VALUES[colors[2]]}" - max_tolerance = MAX_TOLERANCE[colors[3]] - - if len(colors) == 5: - prefix = ( - f"{COLOR_VALUES[colors[0]]}" - f"{COLOR_VALUES[colors[1]]}" - f"{COLOR_VALUES[colors[2]]}" - ) - postfix = f"{'0' * COLOR_VALUES[colors[3]]}" - max_tolerance = MAX_TOLERANCE[colors[4]] + prefix = f"{COLOR_VALUES[colors[0]]}" + else: + prefix = "".join(str(COLOR_VALUES[color]) for color in colors[:-2]) + postfix = f"{'0' * COLOR_VALUES[colors[-2]]}" + max_tolerance = MAX_TOLERANCE[colors[-1]] int_val: int = int(prefix + postfix)