Python I';我试图产生一行代码,返回一个单词的分数,但目前我得到一个错误
输出名称错误:未定义名称“word”Python I';我试图产生一行代码,返回一个单词的分数,但目前我得到一个错误,python,python-3.x,python-requests,nameerror,Python,Python 3.x,Python Requests,Nameerror,输出名称错误:未定义名称“word” 我有点困惑为什么会出现名称错误,有什么建议吗?适当的缩进应该可以解决这个问题 def getWordScore(word): points_total = 0 for letter in word: points_total += getLetterScore.get(letter,0) return points_total brownie_points = getWordScore("BROWNIE") 请注意
我有点困惑为什么会出现名称错误,有什么建议吗?适当的缩进应该可以解决这个问题
def getWordScore(word):
points_total = 0
for letter in word:
points_total += getLetterScore.get(letter,0)
return points_total
brownie_points = getWordScore("BROWNIE")
请注意,您没有提供
getLetterScore
,因此可能存在一些其他问题请修复缩进,我已对其进行了编辑,以显示您粘贴的内容。你可能实际上只是需要缩进一些东西。伟大的,解决了名称错误问题!!
def getWordScore(word):
points_total = 0
for letter in word:
points_total += getLetterScore.get(letter, 0)
return points_total
brownie_points = getWordScore("BROWNIE")