簡體   English   中英

我正在嘗試生成一行代碼,返回一個單詞的分數,但目前我收到一個錯誤

[英]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")

輸出 NameError: name 'word' 未定義

我對為什么會收到 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 ,因此可能存在其他一些問題

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM