Skip to content

Instantly share code, notes, and snippets.

@chelseatroy
Created December 17, 2019 18:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chelseatroy/436b11dd45584c4b2ab03069ce8abab5 to your computer and use it in GitHub Desktop.
Save chelseatroy/436b11dd45584c4b2ab03069ce8abab5 to your computer and use it in GitHub Desktop.
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