
Checkpoint
Checkpoint: The Lighthouse Crew
Each lighthouse in Pythonia has a crew of keepers. The head keeper carries the keys. The Guild wants classes that model a lighthouse and its crew.
This checkpoint uses the whole chapter: composition, inheritance
with super(), a read-only @property and a @classmethod.
Keeper is ready.
Assignment
HeadKeeperis a child class ofKeeper.- Its
__init__(self, name, keys)letsKeeperstore the name, then storeskeys. - Its
describe()returns the parent's description pluswith N keys, e.g.Ada the keeper with 3 keys.
- Its
Lighthouse(island)storesislandand starts an emptycrewlist.hire(keeper)adds a keeper to the crew.roster()returns a list with each keeper'sdescribe()text, in hiring order.sizeis a read-only property: the number of keepers.
- A class method
Lighthouse.from_names(island, names)builds a lighthouse and hires a plainKeeperfor each name.
HeadKeeperis a child class ofKeeper.- Its
__init__(self, name, keys)letsKeeperstore the name, then storeskeys. - Its
describe()returns the parent's description pluswith N keys, e.g.Ada the keeper with 3 keys.
- Its
Lighthouse(island)storesislandand starts an emptycrewlist.hire(keeper)adds a keeper to the crew.roster()returns a list with each keeper'sdescribe()text, in hiring order.sizeis a read-only property: the number of keepers.
- A class method
Lighthouse.from_names(island, names)builds a lighthouse and hires a plainKeeperfor each name.
main.py Python sleeping
Press Run to try your code, then Check to test it.