Skip to content

Commit b59cd49

Browse files
committed
Update resistor_color_expert.py
1 parent f9f3156 commit b59cd49

File tree

1 file changed

+5
-16
lines changed

1 file changed

+5
-16
lines changed

resistor-color-expert/resistor_color_expert.py

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -51,26 +51,15 @@ def resistor_label(colors: list[str]) -> str:
5151
:rtype: str
5252
:raises KeyError: If an unknown color is provided.
5353
"""
54-
prefix: str = ""
5554
postfix: str = ""
5655
max_tolerance: str = ""
5756

5857
if len(colors) == 1:
59-
prefix: str = f"{COLOR_VALUES[colors[0]]}"
60-
61-
if len(colors) == 4:
62-
prefix: str = f"{COLOR_VALUES[colors[0]]}{COLOR_VALUES[colors[1]]}"
63-
postfix = f"{'0' * COLOR_VALUES[colors[2]]}"
64-
max_tolerance = MAX_TOLERANCE[colors[3]]
65-
66-
if len(colors) == 5:
67-
prefix = (
68-
f"{COLOR_VALUES[colors[0]]}"
69-
f"{COLOR_VALUES[colors[1]]}"
70-
f"{COLOR_VALUES[colors[2]]}"
71-
)
72-
postfix = f"{'0' * COLOR_VALUES[colors[3]]}"
73-
max_tolerance = MAX_TOLERANCE[colors[4]]
58+
prefix = f"{COLOR_VALUES[colors[0]]}"
59+
else:
60+
prefix = "".join(str(COLOR_VALUES[color]) for color in colors[:-2])
61+
postfix = f"{'0' * COLOR_VALUES[colors[-2]]}"
62+
max_tolerance = MAX_TOLERANCE[colors[-1]]
7463

7564
int_val: int = int(prefix + postfix)
7665

0 commit comments

Comments
 (0)