# Scrable_Score 9/15

#1

<Below this line, add a link to the EXACT exercise that you are stuck at.>

<In what way does your code behave incorrectly? Include ALL error messages.>
Oops, try again. Your function fails on scrabble_score(“DuNe”). It returns “2” when it should return “5”.

<What do you expect to happen instead?>
Type in DuNe and answer is coming 5 but the error message is saying answer is coming 2. Bug? Or some mistake? @datfatcat

```python

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):
s=0
for c in word:
for a in score:
if c==a:
s += score[a]
return s

print scrabble_score(raw_input('Enter the word : ').lower())

``<do not remove the three backticks above>``

#2

We don’t need to iterate over `score`. It is a look-up table. Just retrieve the score that matches the letter. There is also no need to check anything at this point.

``````for c in word.lower():
s += score[c]``````

#3

Okay, that worked. Thanks.
Could you please explain why we needed to put `word.lower()` in your answers for loop to make it work.
I already made the word in lowercase while taking the word from the user. `scrabble_score(raw_input('Enter the word : ').lower())`. Why was it needed to make the `word` lower again?
Does `raw_input().lower()` doesn’t work in the function call parameter or is it that we need to lower the `word` again?
And what if I wanted to mention both the loops in the program, what would I need to change in my code for both loops to work like I intend to make them work?
I am sorry, I am asking too long question but you are the only hope.

#4

For my own part I like to put any modifiers inside a function rather than in the running code just to keep it simple.

The method works as expected but then the SCT doesn’t see it when it tests the function. By having the method inside the function, all inputs have it applied.

#5

Using for i in word.lower( ) didn’t really work for me so this is my code:
def scrabble_score(word):
total = 0
for i in word:
total = total + score[i.lower( )]

This seems to have done the trick. =)

#6

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

this code works for me

closed #7