Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Rainbow lamp is the class solution in Clear category for Multicolored Lamp by bers2342
class Lamp:
n=0
def light(self):
if self.n%4==0:
self.n+=1
return "Green"
if self.n%4==1:
self.n+=1
return "Red"
if self.n%4==2:
self.n+=1
return "Blue"
if self.n%4==3:
self.n+=1
return "Yellow"
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
lamp_1 = Lamp()
lamp_2 = Lamp()
lamp_1.light() #Green
lamp_1.light() #Red
lamp_2.light() #Green
assert lamp_1.light() == "Blue"
assert lamp_1.light() == "Yellow"
assert lamp_1.light() == "Green"
assert lamp_2.light() == "Red"
assert lamp_2.light() == "Blue"
print("Coding complete? Let's try tests!")
April 4, 2019