scrabble_score Why does this work?


#1

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

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

<What do you expect to happen instead?>
Can someone please explain to me why this works? As far as i can see it’s saying check the dict for
lower case… but what about uppercase?

```python

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

<do not remove the three backticks above>

#2

The dictionary’s keys were arbitrarily set to lower case when we created it. We don’t need to consider upper case in the data, hence forcing the case switch if inputs are upper case.


#3

Had to reread this a couple time, but I understand it now. Thanks alot, mtf.


#4

What is the problem with my program?

def scrabble_score(word):
total = 0
nword = str(word.lower)
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}
for letter in nword:
total += score[letter]
return total


#5

If we are to assume that word is not a string object, then it would not be proper to use a string method on it before converting it to string. Try passing in a number. It will throw a type mismatch error.

Try,

nword = str(word).lower()

Now the word is a string type to which the lower() function may be applied. That’s the only thing that jumps out. The rest of the code looks okay (assuming it is indented as needed).