当在python中运行代码时,会出现多个错误,如果有人能修复它,我们将不胜感激
一个音乐问答游戏的代码错误驻留在行,这意味着分裂成歌曲名称和艺术家的txt文件的内容
txt文件的格式是这样的
歌曲,歌曲艺术家
AuthUsers = {"drew":"pw","masif":"pw","ishy":"pw"}
#authentication
PWLoop = True
while PWLoop:
userName = input("what is your username?")
#asking for password
password = (input("what is the password?"))
if userName in AuthUsers:
if AuthUsers.get(userName) == password:
print("you are allowed to play")
PWLoop = False
else:
print("invalid password")
else:
print("invalid username")
#GAME
#SETTING SCORE VARIBLE
score = 0
#READING SONGS
read = open("SONGS.txt", "r")
songs = read.readline()
songlist = []
for i in range(len(songs)):
songlist.append(songs[i].strip())
while x == 0:
#RANDOMLY CHOSING A SONG
choice = random.choice(songlist)
artist, song = choice.split()
#SPLITTING INTO FIRST WORDS
songs = song.split()
letters = [word[0] for word in songs]
#LOOP
for x in range(0,2):
print(artist, "".join(letters))
guess= str(input(Fore.RED + "guess the song"))
if guess == song:
if x == 0:
score = score + 2
break
if x == 1:
score = score + 1
break
代码应该显示登录
然后比赛
但事实上 显示登录
然后出错
受影响的行应该将txt文件拆分为歌曲和艺术家的第一个字母
目前没有回答
相关问题 更多 >
编程相关推荐