首页 > 解决方案 > 我将如何添加播放列表

问题描述

大家好,我正在制作一个音乐播放器,它有类艺术家和歌曲。我需要添加一个播放列表类,它应该让您能够将我拥有的歌曲添加到一个新的播放列表中,并包含一个打印它包含的所有歌曲的歌曲标题的方法。我很迷茫,我是一个编码的菜鸟,但我已经尽力了。任何帮助都会很棒,我的代码如下,它应该使用类。我对我需要做的事情有一些意见,但我不知道该怎么做。歌曲类将需要存储有关艺术家姓名、歌曲名称和歌曲持续时间等信息...

class Artist:
    def __init__(self, name):
        self.name = name
        self.modules_list = []

    def print_artist_info(self):
        print("Artist name: %s" %self.name)
        print("Artists songs:" )
        i = 0
        for c in self.modules_list:
            i+=1
            print("%d %s" %(i,c.print_module_info()))

    def enrol(self, module_running):#add new song
        self.modules_list.append(module_running)

class Songs:
    def __init__(self, song_title, artist_name, duration):
        self.song_title = song_title
        self.artist_name = artist_name
        self.duration = duration

    def print_module_info(self):#print song info
        return "Title: %s, Artist Name: %s, Duration: %s"  %(self.song_title,self.artist_name, self.duration)


class Playlist:
    def __init__(self, playlist_name):
        self.playlist_name = playlist_name
        self.playlist_list = []

    def print_playlist_info(self):
        playlistname = input("Enter Playlist Name")
        return "Playlist: %s," + (song_title) + (artist_name) + (duration),(self.playlist_name)
        




#def main
def stuff():
    
    song1 = Songs("Twinkle Twinkle Little Star","John Cena","5 Minutes")
    song2 = Songs("Mary Had A Little Lamb ",20,"3 Minutes")
    song3 = Songs("Humpty Dumpty",20,"7 Minutes")

    Artist1 = Artist("Cena John")                                                      
    Artist2 = Artist("John Bob")

    Artist1.enrol(song1)
    Artist1.print_artist_info()
    print("")
    Artist2.enrol(song2)
    Artist2.print_artist_info()
    print("")
    yesorno = input("Do You Want To Add A Song To A Playlist: ")
    if yesorno == "yes":
        song1+()
    if yesorno == "no":
        print("OK")
stuff()


#add new songs to play
#run the artist info
#favourite = playlist()
#favouritwe.addsong rolist(s1)
#favouritwe.addsong rolist(s2)

#main()

标签: pythonpython-3.xclassaudio-player

解决方案


推荐阅读