Scrabble Score


I keep getting the "unsupported operand types for +=: 'int' and 'str"'

My question is what exactly does that error code mean, and what should I look for in my code to fix it? I've gotten that code error a good number of times and just figured it out by messing around for a bit, but I never understood what I was doing. Beyond that, what are the general rules, if any for the += operation?

The goal is just to print the total combined score of the variable word.
My assumption is that after creating an empty list word_value, and then appending it with each letter in word, that the list will read as the numbers assigned to each letter, and then for each item(aka number) in word_value, i could just add it to total.

score = {"a": 1, "c": 3, "b": 3, "e": 1, "d": 2, "g": 2, 
         "f": 4, "i": 1, "h": 4, "k": 5, "j": 8, "m": 3, 
         "l": 1, "o": 1, "n": 1, "q": 10, "p": 3, "s": 1, 
         "r": 1, "u": 1, "t": 1, "w": 4, "v": 4, "y": 4, 
         "x": 8, "z": 10}

def scrabble_score(word):
    for letter in word:
    for item in word_value:
        total += item
    return total


Please paste a link to the exercise.



There is no need to build a list, just accumulate the total. Your code is iterating over the letters of the word, which is enough for the program to do successive loop-ups and accumulate the returned letter score.

total = 0
for letter in word:
    total += score[letter]

Then simply return the total and you're done,


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