From 4b526f1b8668c5dea64108a7fdfb23506750f1ea Mon Sep 17 00:00:00 2001 From: "exercism-solutions-syncer[bot]" <211797793+exercism-solutions-syncer[bot]@users.noreply.github.com> Date: Wed, 8 Oct 2025 01:42:44 +0000 Subject: [PATCH] [Sync Iteration] python/resistor-color/1 --- .../python/resistor-color/1/resistor_color.py | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 solutions/python/resistor-color/1/resistor_color.py diff --git a/solutions/python/resistor-color/1/resistor_color.py b/solutions/python/resistor-color/1/resistor_color.py new file mode 100644 index 0000000..41fa94e --- /dev/null +++ b/solutions/python/resistor-color/1/resistor_color.py @@ -0,0 +1,44 @@ +""" +Utilities for working with the 10-color resistor code. + +Mnemonics map the colors to the numbers, that, when stored +as an array, happen to map to their index in the array: +Better Be Right Or Your Great Big Values Go Wrong. +""" + +COLORS: tuple = ( + "black", + "brown", + "red", + "orange", + "yellow", + "green", + "blue", + "violet", + "grey", + "white", +) + + +def color_code(color: str) -> int: + """ + Return the numeric code (0-9) for a resistor color. + + :param color: Color name. + :type color: str + :returns: Index in the standard 10-color sequence + (0 for 'black' through 9 for 'white'). + :rtype: int + :raises ValueError: If color is not a valid resistor color. + """ + return COLORS.index(color) + + +def colors() -> list: + """ + Return all valid resistor colors in ascending code order. + + :returns: List of color names in order from 'black' (0) to 'white' (9). + :rtype: list + """ + return list(COLORS)