Python 8:Practice Makes Perfect-Scrabble_Score


Good Morning,Friends I am stuck at
Following is my code.Please take a look at it:

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 (score):
        if i in lower:
    return total
print scrabble_score("Hero")
print scrabble_score("pie")
print scrabble_score("xenophobia")

Can any body point to my mistake.Do you think my approach is correct?Because I looked at other solutions and found them to be completely different to my logic..


score is a look-up table. We would never iterate over it.

There is no harm in destroying/modifying the inputs. They are local variables. Think about using the name they begin with.

word = word.lower()

Now if we iterate over the word itself, we can query the table for the letter value.

for letter in word:
    total += score[letter]


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