9. Scrabble score(This is the only one?!)



Oops, try again. Remember to make your function work for upper- and lowercase letters!

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):
    game = 0
    for ltr in word:
        game += score[ltr]
    return game




won't work, it is making ltr lower, but this isn't stored anywhere. you really need to update the ltr variable, use a single equal sign to assign a new value to a variable.


Thanks. I tried:

ltr = ltr.lower()


that should do the trick. I assume you passed it?


The above fix should do the trick! Another way I found to complete this problem is to make the whole input lowercase in the beginning, so the loop doesn't have to modify it each time:

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


you can even shorten that by doing lower at the start of the loop:

for i in word.lower():

this will convert the word into lower, and then loop over it


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