Skip to content

Instantly share code, notes, and snippets.

@Tinitto
Created September 20, 2016 22:45
Show Gist options
  • Save Tinitto/cb5eae0fc961a3f035ce2b6e9c9bbce2 to your computer and use it in GitHub Desktop.
Save Tinitto/cb5eae0fc961a3f035ce2b6e9c9bbce2 to your computer and use it in GitHub Desktop.
##Have a band, hire musicians and fire them using OOP
import random
class Musician:
"""docstring for ClassName"""
def __init__(self, name, specialization, sound):
self.name = name
self.specialization = specialization
self.sound = sound
class Guitarist(Musician):
"""docstring for guitarist"""
def __init__(self, tone):
super(Guitarist, self).__init__(name = "", specialization = "Guitarist", sound = "ting ting")
self.tone = tone
class Drummer(Musician):
"""docstring for Drummer"""
def __init__(self, _type):
super(Drummer, self).__init__(name = "", specialization = "Drummer", sound = "boom boom")#super is used to override the parent class
self._type = _type
class Music:
def __init__(self, drumInterval):
self.drumInterval = drumInterval
class Band:
def __init__(self, maxSize, currentSize, musicType, musicians = [], structure =[]):
self.maxSize = maxSize
self.currentSize = currentSize
self.musicType = musicType
self.musicians = musicians
self.structure = structure
def hireMusician(self, musician):
self.musicians.append(musician)
self.structure.append(musician.specialization)
self.currentSize += 1
def fireMusician(self, musician):
self.musicians.remove(musician)
self.structure.remove(musician.specialization)
self.currentSize -= 1
def pickInterval(self):
interval = 0 #the number of other sounds before the sound of the drum
if self.musicType.lower() == "rock":
interval = 1
elif self.musicType.lower() == "slow":
interval = 4
elif self.musicType.lower() == "jazz":
interval = 3
else:
interval = 2
return interval
if __name__ == '__main__':
Paul = Guitarist("bass")
Paul.name = "Paul"
John = Guitarist("solo")
John.name = "John"
Adam = Drummer("jazz drums")
Adam.name = "Adam"
Harry = Drummer("rock drums")
Harry.name = "Harry"
Jovia = Musician("Jovia", "Soloist", "Haaaa-le-llu-jah!")
Carol = Musician("Carol", "Pianist", "tuulululu taalala")
allMusicians = [Paul, John, Adam, Harry, Jovia, Carol]
randomMusicians1 = random.sample(allMusicians, allMusicians.__len__())
randomMusicians2 = random.sample(allMusicians, allMusicians.__len__())
#Instantiation of the bands,one jazz, the other rock
harmonics = Band(3, 0, "jazz", [], [])
blackHawks = Band(5, 0, "rock", [], [])
#Hiring musicians
for eachMusician in randomMusicians1:#picking randomly but not going above the maximum value; with one of each type of musician
if (harmonics.structure.count(eachMusician.specialization) < 1) and (harmonics.currentSize < harmonics.maxSize):
harmonics.hireMusician(eachMusician)
for eachMusician in randomMusicians2:#picking randomly but not going above the maximum value; with one of each type of musician
if (blackHawks.structure.count(eachMusician.specialization) < 1) and (blackHawks.currentSize < blackHawks.maxSize):
blackHawks.hireMusician(eachMusician)
print("\nHarmonics:\n...................")
for eachMusician in harmonics.musicians:
print(eachMusician.name)
print("\nBlackHawks:\n....................")
for eachMusician in blackHawks.musicians:
print(eachMusician.name)
#firing musicians and replacing them
for eachMusician in harmonics.musicians:
if eachMusician.specialization == "Drummer":
if eachMusician._type == "rock drums":
harmonics.fireMusician(eachMusician) #fire one not suited for the music type
for everyMusician in allMusicians:
if everyMusician.specialization == "Drummer":
if everyMusician._type == "jazz drums":
harmonics.hireMusician(everyMusician) #replace the fired
for eachMusician in blackHawks.musicians:
if eachMusician.specialization == "Drummer":
if eachMusician._type == "jazz drums":
blackHawks.fireMusician(eachMusician) #fire one not suited for the music type
for everyMusician in allMusicians:
if everyMusician.specialization == "Drummer":
if everyMusician._type == "rock drums":
blackHawks.hireMusician(everyMusician) #replace the fired appropriately
print("\nNew Harmonics:\n..............")
for eachMusician in harmonics.musicians:
print(eachMusician.name)
print("\nNew blackHawks:\n....................")
for eachMusician in blackHawks.musicians:
print(eachMusician.name)
#Playing Music
print("\nHarmonics' music:\n" + "......................................................")
count1 = 0
count2 = 0
drum = ""
while count1 < 3:
while count2 < harmonics.pickInterval():
for eachMusician in harmonics.musicians:
if eachMusician.specialization.lower() != "drummer":
print(eachMusician.sound)
else:
drum = eachMusician.sound;
count2 += 1
if drum != "":
print("\n" + drum + "\n")
count1 += 1
count2 = 0
print("\nBlackHawks' music:\n"+ "......................................................")
count1 = 0
count2 = 0
drum = ""
while count1 < 3:
while count2 < blackHawks.pickInterval():
for eachMusician in blackHawks.musicians:
if eachMusician.specialization.lower() != "drummer":
print( eachMusician.sound)
else:
drum = eachMusician.sound;
count2 += 1
if drum != "":
print("\n" + drum + "\n")
count1 += 1
count2 = 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment