Scrabble Score


#1


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):
    word_value=[]
    total=0
    for letter in word:
        word_value.append(letter)
    for item in word_value:
        total += item
    return total


#2

Please paste a link to the exercise.


#3

https://www.codecademy.com/courses/python-intermediate-en-rCQKw/1/3?curriculum_id=4f89dab3d788890003000096


#4

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,


#5

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