Hello fellas,
I am having a trouble with this little code can anyone hint what's happening why the score is always 87 the sum of all scores?

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 i in word:
        result = 0
        key = i.lower()
        for key in score:
            result += score[key]
    return result
print scrabble_score("A")


because here:

for key in score:

you loop over all the keys in the score dictionary, and then add the values to total

You should instead loop over word, and add the score of each letter in word to total


You almost got it, :slight_smile:

  1. These two variables should be outside your two loops,

but, the key variable should be word instead,

word = word.lower()

And you need to do a little verification so all you need is an if statement,

if key == i:

altogether your two for loops would now look like,

for i in word:
        for key in score:
            if key == i:
                result += score[key]
return result


Ok, I owe you one goat and one potato my friend :smiley:

Seriously thanks


Ya but the verification was still necessary.Thanks bro