Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python I';我试图产生一行代码,返回一个单词的分数,但目前我得到一个错误_Python_Python 3.x_Python Requests_Nameerror - Fatal编程技术网

Python I';我试图产生一行代码,返回一个单词的分数,但目前我得到一个错误

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") 请注意

输出名称错误:未定义名称“word”


我有点困惑为什么会出现名称错误,有什么建议吗?

适当的缩进应该可以解决这个问题

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")