Advertisement
horozov86

class_Album

Jun 28th, 2023 (edited)
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.34 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.        
  8.     def add_song(self, song):
  9.         if song.single:
  10.             return f"Cannot add {song.name}. It's a single"
  11.         if self.published:
  12.             return "Cannot add songs. Album is published."
  13.         if song in self.songs:
  14.             return f"Song is already in the album."
  15.            
  16.         self.songs.append(song)
  17.         return f"Song {song.name} has been added to the album {self.name}."
  18.        
  19.     def remove_song(self, song_name):
  20.         if self.published:
  21.             return f"Cannot remove songs. Album is published."
  22.         for song in self.songs:
  23.             if song.name = song_name:
  24.                 self.songs.remove(song)
  25.                 return f"Removed song {song.name} from album {self.name}."
  26.                
  27.         return f"Song is not in the album."
  28.        
  29.     def publish(self):
  30.         if self.published:
  31.             return f"Album {self.name} is already published."
  32.         self.published = True
  33.         return f"Album {self.name} has been published."
  34.            
  35.     def details(self):
  36.         result += f"Album {self.name}\n"
  37.         for song in self.songs:
  38.             result += f'== {song.get_info()}\n'
  39.         return result.strip()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement