基本上,我正在制作一个“音乐播放器菜单”,我需要创建一个功能,在目录中按姓名、作者或流派搜索音乐,如果其中一个元素与特定歌曲匹配,复制所有这些元素并将其添加到播放列表中
这是将歌曲添加到音乐目录的功能:
Cat = [] #This is the music catalogue list
def AddSong():
songs = [] #This is where I'm storing the songs
print('--- Add song ---')
while True:
name = input('Songs name: ')
author = input("Author: ")
genre = input("Genre: ")
length = input("Song length: ")
songs.append(name)
songs.append(author)
songs.append(genre)
songs.append(length)
Cat.append(songs)
return
新增歌曲如下所示,['Crazy train','Ozzy Osbourne','Heavy metal','4:56']在Cat列表中
这是创建播放列表的功能:
Play = []
if len(Cat) > 0:
print('--- Add a playlist ---')
else:
print("Error: There's not songs")
return
namep = input("Please, introduce a name for your new playlist: ")
Play.append(namep)
Cata()
i = int(input("Please, introduce the correspondent number to add the song to the playlist"))
Play.append(Cat[i-1])
if len(Cat) > 0:
print('=== Available Playlist ===')
for p in Cat:
# print(str(n)+'. '+lista[0])
print(f'{"Playlist: "}{Play[0]}')
print(f'{"Name: "}{p[0]}')
print(f'{"Author: "} {p[1]}')
print(f'{"Genre: "} {p[2]}') # <--- formatted string
print(f'{"Length: "}{p[3]}')
return True
我设法通过索引将歌曲的所有信息添加到播放列表中,但我需要知道如果用户输入的姓名、作者或流派与目录中的歌曲匹配,是否有办法将歌曲添加到播放列表中
提前谢谢
试试这个:
相关问题 更多 >
编程相关推荐