Advertisement
pacho_the_python

band

Jul 3rd, 2022
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.91 KB | None | 0 0
  1. class Band:
  2.     def __init__(self, name):
  3.         self.name = name
  4.         self.albums = []
  5.  
  6.     def add_album(self, album):
  7.         if album in self.albums:
  8.             return f"Band {self.name} already has {album.name} in their library."
  9.         self.albums.append(album)
  10.         return f"Band {self.name} has added their newest album {album.name}."
  11.  
  12.     def remove_album(self, album_name):
  13.         for album in self.albums:
  14.             if album.name == album_name:
  15.                 if album.published:
  16.                     return "Album has been published. It cannot be removed."
  17.                 self.albums.remove(album)
  18.                 return f"Album {album_name} has been removed."
  19.         return f"Album {album_name} is not found."
  20.  
  21.     def details(self):
  22.         result = f"Band {self.name}\n"
  23.         for album in self.albums:
  24.             result += album.details() + "\n"
  25.         return result.strip()
  26.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement