这是我的代码:
OR
我的代码的功能是使用我已经拥有的歌曲的用户的播放列表生成器。这一切都可以到现在为止,但是当试图允许用户在代码的这一部分中查看他们选择的播放列表时:
cont = "y"
cont1 = "0"
cont2 = "yes"
log = 0
data = open("songs.txt", "r")
songs = data.readlines()
songs.sort()
while cont1 == "0":
cont = input("Do you want to make a playlist? [Y or N]") #Need to change to change cont1 if a playlist is not wanted to be created
if cont == "y":
new = "playlist" + str(log) + ".txt"
print(new, "Please remember the number. Thanks")
log = log + 1
else:
break
while cont == "y":
print ("1. ", songs[0],"2. ", songs[1],"3. ", songs[2],"4. ", songs[3],"5. ", songs[4],"6. ", songs[5],"7. ", songs[6],"8. ", songs[7],"9. ", songs[8],"10. ", songs[9],"11. ", songs[10],"12. ", songs[11],"13. ", songs[12],"14. ", songs[13],"15. ", songs[14],"16. ", songs[15],"17. ", songs[16],"18. ", songs[17],"19. ", songs[18],"20. ", songs[19])
choice = int(input("Please enter the first choice of song you would like in your playlist [Type the allocated number please]"))
choice1 = choice - 1
with open("playlist" + str(log) + ".txt", "a") as playlist:
playlist.write(str(songs[choice1]))
cont = input("Do you want to add another song? [Y or N]")
if cont == "n":
break
view = input("Which playlist would you like to view? Please enter the number
you were given before.")
with open("playlist" + str(view) + ".txt", "a") as see:
print(see)
我收到一条错误消息:
view = input("Which playlist would you like to view? Please enter the number
you were given before.")
with open("playlist" + str(view) + ".txt", "a") as see:
print(see)
这对任何人都有意义吗?
谢谢!
顺便说一句,songs.txt中包含20首歌曲的列表。干杯!的
答案 0 :(得分:0)
我想这里可能有几件事。 <div id="header_block">
<div id="hb_title">
</div>
</div>
未以可读模式打开,因此playlist2.txt
需要open
而不是r
。 a
是一个文件对象,因此see
需要print
来打印文件内容。