Scrabble_score


#1




I hoped I had figured it out, but the result keeps returning zero instead of the scrabble score. I hope someone can help by pointing out my mistake, so I can figure out how to fix it.

The error message I get is:

Oops, try again. Your function fails on scrabble_score("pie"). It returns "0" when it should return "5".

Thanks in advance :slight_smile:


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):
    value = 0
    word.lower()
    
    for i in word:
        for v in score:
            if i == score[v]:
                value = value + score[v]
            
    return value


#2

why two loops? you can simply use i to get the value associated with the key:

for i in word:
   value += score[i]

since score is a dictionary, once you have the letter, you have the key value, which you can use to retrieve the value


#3

Thanks a lot! Got it working now (after also fixing the word to str() so it could actually convert the input to lower case).


#4