Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Multicolored Lamp by UpwardTrajectory
class Lamp:
"""A lamp that changes colors in a specific sequence"""
def __init__(self, colors=None, i=None):
if type(colors) is list:
self.colors = colors
else:
self.colors = ["Green", "Red", "Blue", "Yellow"]
if i:
self.i = i
else:
self.i = -1
def light(self):
"""Once toggled 'ON', this lamp cannot be turned 'OFF'
We are sorry for the inconvenience."""
self.i += 1
return self.colors[self.i % len(self.colors)]
Sept. 16, 2019