Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Band:
- def __init__(self, name: str, time: int):
- self.name = name
- self.time = time
- self.members = list()
- all_bands = list()
- def band_exist(b):
- for band in all_bands:
- if band.name == b:
- return band
- def add_band_and_members(b, b_m):
- if band_exist(b):
- current_band = band_exist(b)
- for member in b_m:
- if member not in current_band.members:
- current_band.members.append(member)
- else:
- new_band = Band(b, 0)
- for member in b_m:
- if member not in new_band.members:
- new_band.members.append(member)
- all_bands.append(new_band)
- def update_or_add_band_time(b_n, p_t):
- existing_band = band_exist(b_n)
- if existing_band:
- existing_band.time += p_t
- else:
- all_bands.append(Band(name=b_n, time=p_t))
- def total_time():
- t_time = 0
- for b in all_bands:
- t_time += b.time
- return t_time
- while True:
- txt = input()
- if txt == "start of concert":
- break
- else:
- txt_split = txt.split("; ")
- command = txt_split[0]
- if command == "Add":
- band_name = txt_split[1]
- band_members = txt_split[2].split(", ")
- add_band_and_members(band_name, band_members)
- elif command == "Play":
- band_name = txt_split[1]
- play_time = int(txt_split[2])
- update_or_add_band_time(band_name, play_time)
- total_time = total_time()
- print(f"Total time: {total_time}")
- all_bands = sorted(all_bands, key=lambda x: (-x.time, x.name))
- for band in all_bands:
- print(f"{band.name} -> {band.time}")
- band_to_print = band_exist(input())
- print(f"{band_to_print.name}")
- for member in band_to_print.members:
- print(f"=> {member}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement