Scrabble score - just the upper and lower case letters


#1



Hello house, i believe i have the right code. but how do i make the function work for Upper case and lower cas letters.. because i get this error if try running it on codecademy :

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


#2

look what happens when i use an uppercase letter:

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

i get a keyerror, A is not in the score dictionary.

you could simply convert word to lowercase?


#3

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