Advertisement
KNenov96

Untitled

Mar 31st, 2023
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.50 KB | None | 0 0
  1.     def start_concert(self, concert_place: str, band_name: str):
  2.         band = [bands for bands in self.bands if bands.name == band_name][0]
  3.  
  4.         available_musicians = [musician for musician in band.members]
  5.         types_musicians = ['Singer', 'Guitarist', 'Drummer']
  6.         if not all(item in (x.__class__.__name__ for x in available_musicians) for item in types_musicians ):
  7.             raise Exception(f"{band_name} can't start the concert because it doesn't have enough members!")
  8.  
  9.         concert = [concert for concert in self.concerts if concert.place == concert_place][0]
  10.         played_genre = concert.genre
  11.         available_skills = []
  12.         for skill in [musician.skills for musician in available_musicians]:
  13.                 available_skills.extend(skill)
  14.  
  15.         needed_skills = {"Rock": ["play the drums with drumsticks", "sing high pitch notes", "play rock"],
  16.                          "Metal": ["play the drums with drumsticks", "sing low pitch notes", "play metal"],
  17.                          "Jazz": ["play the drums with drum brushes", "sing high pitch notes", "sing low pitch notes",
  18.                                   "play jazz"]}
  19.  
  20.         if not set(needed_skills[played_genre]).issubset(set(available_skills)):
  21.             raise Exception(f"The {band_name} band is not ready to play at the concert!")
  22.  
  23.         profit = (concert.audience * concert.ticket_price) - concert.expenses
  24.  
  25.         return f"{band_name} gained {profit:.2f}$ from the {concert.genre} concert in {concert_place}."
  26.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement