我正在尝试生成一行代码 returns 一个单词的分数,但此刻我收到一个错误
I'm trying to produce a line of code the returns the score of a word but at the moment I am getting an error
def getWordScore(word):
points_total = 0
for letter in word:
points_total += getLetterScore.get(letter,0)
return points_total
brownie_points = getWordScore("BROWNIE")
output NameError: name 'word' is not defined
我有点困惑为什么会收到 nameError,有什么建议吗?
适当的缩进应该可以解决问题
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")
output NameError: name 'word' is not defined
我有点困惑为什么会收到 nameError,有什么建议吗?
适当的缩进应该可以解决问题
def getWordScore(word):
points_total = 0
for letter in word:
points_total += getLetterScore.get(letter, 0)
return points_total
brownie_points = getWordScore("BROWNIE")
请注意您没有提供 getLetterScore
,所以可能还有一些其他问题