# Python 8:Practice Makes Perfect-Scrabble_Score

#1

Good Morning,Friends I am stuck at https://www.codecademy.com/courses/python-intermediate-en-rCQKw/1/3?curriculum_id=4f89dab3d788890003000096#
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):
total=0
lower=word.lower()
for i in (score):
if i in lower:
total=total+score[i]

print scrabble_score("Hero")
#score=7
print scrabble_score("pie")
#score=5
print scrabble_score("xenophobia")
#score=24``````

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..

#2

`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]``````

#3

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