Feb-05-2024, 03:27 PM
Although I've been coding with Python for a number of years now, I've never constructed a
Class
before. This is my first attempt.class Resister: def __init__(self, band1, band2, band3): bands = { "black": 0, "brown": 1, "red": 2, "orange": 3, "yellow": 4, "green": 5, "blue": 6, "violet": 7, "gray": 8, "white": 9, } multi = { "black": 1, "brown": 10, "red": 100, "orange": 1000, "yellow": 10 * 1000, "green": 100 * 1000, "blue": 1000000, "violet": 10 * 1000000, } base_value = (bands[band1] * 10) + bands[band2] self.value = base_value * multi[band3] r1 = Resister("blue", "gray", "red") print(r1.value)The 'subject' here is not the point (I know that there's a Python library for this kind of thing), rather is this the way to go, or is there a better way to do this?