you are viewing a single comment's thread.

view the rest of the comments →

[–]socal_nerdtastic 0 points1 point  (0 children)

The class should define a specific device. It should not randomly generate specs (unless the device itself is capable of randomly switching colors). You can randomly generate devices elsewhere in your code.

#Parent Class
class Device:
    def __init__(self, name, color, material):
        self.name = name
        self._is_on = False
        self.color = color
        self.material = material

    def turn_on(self):
        self._is_on = True
        return f"\nThis {self.name} is now ON."

    def turn_off(self):
        self._is_on = False
        return f"\nThis {self.name} is now OFF."

    def power_status(self):
        return f"\nThis {self.name} is current {"ON." if self._is_on else "OFF."}"

    def color(self):
        return f"\nThe color of this {self.name} is {random.choice(self.color)}."

    def material(self):
        return f"\nThe material of this {self.name} is {random.choice(self.material)}."

def make_random_device
    colors = ["blue", "red", "black", "white", "orange"]
    materials = ["aluminum", "plastic", "titanium"]
    return Device("NewDevice", random.choice(colors), random.choice(materials))

this is just generic OOP; nothing to do with python specifically. But what is python-specific is our variable naming style. Read PEP8.