Created
December 17, 2019 18:58
-
-
Save chelseatroy/436b11dd45584c4b2ab03069ce8abab5 to your computer and use it in GitHub Desktop.
Storing State
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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