From b59cd490c9a28156b51e0fbf4b8548d06dc47912 Mon Sep 17 00:00:00 2001 From: Egor Kostan Date: Sun, 23 Nov 2025 20:58:00 -0800 Subject: [PATCH] Update resistor_color_expert.py --- .../resistor_color_expert.py | 21 +++++-------------- 1 file changed, 5 insertions(+), 16 deletions(-) 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)