update from Atlas
This commit is contained in:
26
08-obj-ref/twilight_bus.py
Normal file
26
08-obj-ref/twilight_bus.py
Normal file
@@ -0,0 +1,26 @@
|
||||
"""
|
||||
>>> basketball_team = ['Sue', 'Tina', 'Maya', 'Diana', 'Pat']
|
||||
>>> bus = TwilightBus(basketball_team)
|
||||
>>> bus.drop('Tina')
|
||||
>>> bus.drop('Pat')
|
||||
>>> basketball_team
|
||||
['Sue', 'Maya', 'Diana']
|
||||
"""
|
||||
|
||||
# BEGIN TWILIGHT_BUS_CLASS
|
||||
class TwilightBus:
|
||||
"""A bus model that makes passengers vanish"""
|
||||
|
||||
def __init__(self, passengers=None):
|
||||
if passengers is None:
|
||||
self.passengers = [] # <1>
|
||||
else:
|
||||
self.passengers = passengers #<2>
|
||||
|
||||
def pick(self, name):
|
||||
self.passengers.append(name)
|
||||
|
||||
def drop(self, name):
|
||||
self.passengers.remove(name) # <3>
|
||||
# END TWILIGHT_BUS_CLASS
|
||||
|
||||
Reference in New Issue
Block a user