آلبوم آهنگ

mail@pastecode.io avatar
unknown
python
2 years ago
3.1 kB
1
Indexable
Never
class song:

    def __init__(self, name):
        self.name = name


class album:

    def __init__(self, name, year):
        self.name = name
        self.publish_year = year
        self.album_songs = []

    def AddSong(self, name):
        self.album_songs.append(name)

    def PrintSongs(self):
        if len(self.album_songs) == 0:
            print("no songs found in" , self.name)
        for i in self.album_songs:
            print(i.name)


class band:
    def __init__(self, name):
        self.name = name
        self.singles = []
        self.albums = []

    def AddSingle(self, name):
        self.singles.append(name)

    def AddAlbum(self, name):
        self.albums.append(name)

    def PrintAlbums(self):
        if len(self.albums) == 0:
            print("no albums by" , self.name , "found")
        for i in self.albums:
            print(i.name , "published at" , i.publish_year)

    def PrintSingles(self):
        if len(self.singles) == 0:
            print("no singles found by" , self.name)
        for i in self.singles:
            print(i.name)


def main():
    n = int(input())
    bands = []
    albums = []
    for i in range(0, n):
        command = input().split()
        if command[0] == "add":
            if command[1] == "band":
                tmp = band(command[2])
                bands.append(tmp)
            if command[1] == "album":
                for i in bands:
                    if i.name == command[7]:
                        tmp = album(command[2],int(command[5]))
                        albums.append(tmp)
                        i.AddAlbum(tmp)
            if command[1] == "song":
                for i in bands:
                    if i.name == command[4]:
                        for j in i.albums:
                            if j.name == command[6]:
                                tmp = song(command[2])
                                j.AddSong(tmp)
            if command[1] == "single":
                for i in bands:
                    if i.name == command[4]:
                        tmp = song(command[2])
                        i.AddSingle(tmp)
        if command[0] == "print":
            if command[2] == "albums":
                found = False
                for i in bands:
                    if i.name == command[1]:
                        i.PrintAlbums()
                        found = True
                if found == False:
                    print("no albums by" , command[1] ,"found")
            if command[1] == "songs":
                found = False
                for i in albums:
                    if i.name == command[3]:
                        i.PrintSongs()
                        found = True
                if found == False:
                    print("no songs found in" , command[3])
            if command[1] == "singles":
                found = False
                for i in bands:
                    if i.name == command[3]:
                        i.PrintSingles()
                        found = True
                if found == False:
                    print("no singles found by" , command[3])


main()