Created
December 19, 2016 22:13
-
-
Save j10sanders/f20b5ca0f8920bd29f71a9d44bef6ee0 to your computer and use it in GitHub Desktop.
old thinkful project
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 Musician(object): | |
def __init__(self, sounds): | |
self.sounds = sounds | |
def solo(self, length): | |
for i in range(length): | |
print(self.sounds[i % len(self.sounds)], end=" ") | |
print() | |
class Bassist(Musician): # The Musician class is the parent of the Bassist class | |
def __init__(self): | |
# Call the __init__ method of the parent class | |
super().__init__(["Twang", "Thrumb", "Bling"]) | |
class Guitarist(Musician): | |
def __init__(self): | |
# Call the __init__ method of the parent class | |
super().__init__(["Boink", "Bow", "Boom"]) | |
def tune(self): | |
print("Be with you in a moment") | |
print("Twoning, sproing, splang") | |
class Drummer(Musician): | |
def __init__(self): | |
super().__init__(["Crash", "Bump", "Boom"]) | |
def count(self): | |
print("ONE TWO THREE FOUR!") | |
class Band(object): | |
def __init__(self): | |
self.members = {} | |
def hire(self, role, musician): | |
self.members[role] = musician | |
def fire(self, role, musician): | |
if role in self.members: | |
if self.members[role] == musician: | |
del self.members[role] | |
else: | |
print("He's not in the band") | |
def play_music(self, length): | |
self.members['drummer'].count() | |
for role, musician in self.members.items(): | |
musician.solo(length) | |
if __name__ == '__main__': | |
jayson = Drummer() | |
nigel = Guitarist() | |
jon = Bassist() | |
rude_bois = Band() | |
rude_bois.hire('drummer', jayson) | |
rude_bois.hire('guitarist', nigel) | |
rude_bois.hire('bassist', jon) | |
rude_bois.play_music(4) | |
rude_bois.fire('guitarist', "april") | |
print(len(rude_bois.members)) | |
rude_bois.fire("guitarist", nigel) | |
print(len(rude_bois.members)) | |
rude_bois.play_music(4) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment