-
-
Save jmsword/bec4c682ca1195950f5e52050a4497ad to your computer and use it in GitHub Desktop.
Band project
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
#constructing classes and objects | |
class musician(object): | |
#defines the musician object and initiates a solo method for all musicians | |
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 basist(musician): | |
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("Twoing, sproing, splang") | |
class drummer(musician): | |
def __init__(self): | |
#Call the __init__ method of the parent class | |
super(). __init__(["Boom", "Bang", "Tist", "Da-Dum-Tist"]) | |
def count(self): | |
print("And a one, two, three, four!") | |
def on_fire(self): | |
print("I'm on fire!") | |
class band(object): | |
def __init__(self): | |
#provides a dict to add musicians to when they are hired | |
self.members = {} | |
def hire(self, role, musician): | |
#hires musicians and adds them to the band dict | |
self.members[role] = musician | |
def play(self, length): | |
#initiates the count from the drummer then instructs the musicians to solo | |
self.members['drummer'].count() | |
self.members['drummer'].solo(5) | |
self.members['guitarist'].solo(5) | |
self.members['basist'].solo(5) | |
def fire(self, role, musician): | |
#tells a band member they are fired! | |
if role in self.members: | |
print(self.members[role] + "You are fired!") | |
if __name__ == '__main__': | |
jeff = guitarist() | |
ryan = drummer() | |
danny = basist() | |
our_band = band() | |
our_band.hire('drummer', ryan) | |
our_band.hire('guitarist', jeff) | |
our_band.hire('basist', danny) | |
our_band.play(5) | |
our_band.fire('guitarist', jeff) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment