【问题标题】: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我正在尝试生成一行代码来返回单词的分数,但目前我遇到了错误
【发布时间】:2020-11-17 21:29:34
【问题描述】:
def getWordScore(word):
    points_total = 0 
for letter in word:
      points_total += getLetterScore.get(letter,0)
return points_total
brownie_points = getWordScore("BROWNIE")

输出 NameError: name 'word' is not defined

我对为什么会收到 nameError 感到有些困惑,有什么建议吗?

【问题讨论】:

  • 请修正缩进,我已经对其进行了编辑以显示您粘贴的内容。你可能实际上只是需要缩进一些东西

标签: python python-3.x python-requests nameerror


【解决方案1】:

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

    def getWordScore(word):
        points_total = 0
        for letter in word:
            points_total += getLetterScore.get(letter, 0)
        return points_total
brownie_points = getWordScore("BROWNIE")

请注意您没有提供getLetterScore,因此可能存在一些其他问题

【讨论】:

  • 太好了,解决了nameError问题!!
猜你喜欢
  • 1970-01-01
  • 2010-11-09
  • 2021-08-07
  • 1970-01-01
  • 2022-11-11
  • 1970-01-01
  • 2020-04-26
  • 2022-06-11
  • 1970-01-01
相关资源
最近更新 更多