Created
September 8, 2021 08:26
-
-
Save RyanKor/b0e422262f984db8653f59361278a4ce to your computer and use it in GitHub Desktop.
This file contains 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 HauntedBus: | |
def __init__(self, passengers=[]): | |
self.passengers = passengers | |
def pick(self, name): | |
self.passengers.append(name) | |
def drop(self, name): | |
self.passengers.remove(name) | |
bus1 = HauntedBus(['Alice', "Bill"]) | |
print(bus1.passengers) | |
bus1.pick("Charlie") | |
bus1.drop("Alice") | |
print(bus1.passengers) | |
bus2 = HauntedBus() | |
bus2.pick("Carrie") | |
print(bus2.passengers) | |
bus3 = HauntedBus() | |
print(bus3.passengers) | |
bus3.pick("Dave") | |
print(bus2.passengers) | |
print(bus2.passengers is bus3.passengers) | |
print(bus1.passengers) | |
# ['Alice', 'Bill'] | |
# ['Bill', 'Charlie'] | |
# ['Carrie'] | |
# ['Carrie'] | |
# ['Carrie', 'Dave'] | |
# True | |
# ['Bill', 'Charlie'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment