9. scrabble_score (quick question)


When my code looks like this:

def scrabble_score(word):
    word = word.lower()
    total = 0
    for i in word:
        for j in score:
            if i == j:
                total += score[j]
            return total

the function returns 0 for any word.

When I remove an indentation from the last line it returns a score lower than it should, and when I remove another indentation from the last line it finally works as expected. Why do I have to return the total two spaces back instead of where it is currently?


With where your return statement is, it will return a result after it has performed the if condition whereas what you really want returned is what lies in the output of the first for loop.

Hence, the need for you to do that.

Hope this helps! :slight_smile:


It did help, thanks!


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.