pacho_the_python

album

Jul 3rd, 2022
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.27 KB | None | 0 0
  1. class Album:
  2.     def __init__(self, name, *songs):
  3.         self.name = name
  4.         self.songs = list(songs)
  5.         self.published = False
  6.  
  7.     def add_song(self, song):
  8.         if song.single:
  9.             return f"Cannot add {song.name}. It's a single"
  10.         if self.published:
  11.             return "Cannot add songs. Album is published."
  12.         if song in self.songs:
  13.             return "Song is already in the album."
  14.         self.songs.append(song)
  15.         return f"Song {song.name} has been added to the album {self.name}."
  16.  
  17.     def remove_song(self, song_name):
  18.         if self.published:
  19.             return "Cannot remove songs. Album is published."
  20.         for song in self.songs:
  21.             if song.name == song_name:
  22.                 self.songs.remove(song)
  23.                 return f"Removed song {song_name} from album {self.name}."
  24.         return "Song is not in the album."
  25.  
  26.     def publish(self):
  27.         if self.published:
  28.             return f"Album {self.name} is already published."
  29.         self.published = True
  30.         return f"Album {self.name} has been published."
  31.  
  32.     def details(self):
  33.         result = f"Album {self.name}\n"
  34.         for song in self.songs:
  35.             result += f"== {song.get_info()}\n"
  36.         return result.strip()
  37.  
Advertisement
Add Comment
Please, Sign In to add comment