class TrafficLight:
    def __init__(self):
        self.location = 0
        self.color = ["Red", "Green", "Yellow"]

    def next_step(self):
        print(self.color[self.location])
        self.location += 1
        if self.location == len(self.color):
            self.location = 0

    def emergency_mode(self):
        self.location = 0
        print(self.color[self.location])


traffic = TrafficLight()
traffic.next_step()
traffic.next_step()
traffic.next_step()
traffic.next_step()

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: