Scrabble - why do I need to have the 'for key in char' line


#1

I was pretty sure I nailed this one on my initial attempt, but it didn't work. After I searched the forums I see that I was missing the 'for key in char' line. My question is WHY I need that? Why doesn't the "total+=score[key]" in my initial code accomplish this?

Thanks!

My initial code:

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=word.lower()
    total=0
    for char in word:
        total+=score[key]
    return total

The correct code:

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=word.lower()
    total=0
    for char in word:
        for key in char:
            total+=score[key]
    return total

#2

the reason you need
for key in char
is that you didn't define "key"

simply replace key by char in
total+=score[char]

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


#3

Oh, that makes sense. Thank you!