Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Storing State
class TrafficLight:
def __init__(self, name, state):
self.name = str(name)
self.current_state = state
def progress(self):
if self.current_state == "green":
print(self.name + " light yellow")
self.current_state = "yellow"
elif self.current_state == "yellow":
print(self.name + " light red")
self.current_state = "red"
elif self.current_state == "red":
print(self.name + " light green")
self.current_state = "green"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment