Python测验中的str对象不可调用

2024-09-18 18:44:04 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在做一个测验,但它一直说str object not callable im guess,因为我已经重新分配了songn和guess,但我不知道该怎么改

songn = str(song.readlines()[randNum]) #to match song line with artist
reader= csv.reader(f)
for row in reader:
   print (songn[0]) #prints first letter of random song

artist = open("artistList.csv", "rt")
artistname = artist.readlines()[randNum] #to match song line with artist
print(artistname)
artist.close()
total=2 #number of guesses


guess = input("What is the song called?\n> ").lower()
print("guess is '%s' and songn is '%s'"(guess,songn))

错误在这行

print("guess is '%s' and songn is '%s'"(guess,songn))

Tags: csvtosongartistismatchwithline
1条回答
网友
1楼 · 发布于 2024-09-18 18:44:04

检查带有函数print()的行的语法

print("guess is '%s' and songn is '%s'"(guess,songn))

应该在字符串和要打印的变量之间使用“%”

print("guess is '%s' and songn is '%s'" % (guess,songn))

相关问题 更多 >