我有一个变量,它在函数内部的while循环条件下使用。运行该函数时出现错误消息:分配前引用了本地变量'audioLength'
song = input("Enter a song to play: ")
songFile = song + ".mp3"
mp3File = MP3(songFile)
audioLength = int(mp3File.info.length)
def play():
pygame.mixer.music.load(song + ".mp3")
pygame.mixer.music.play()
while audioLength != 0:
audioLength -= 1
time.sleep(1)
我不确定为什么它认为audioLength
是局部变量,我该如何解决?