scrabble_score (why doesn't this work?)


#1
def scrabble_score(word):
    fscore = 0
    for i in word:
        score[(str(i).lower())] += fscore
        print fscore
        return fscore

To my eyes, this should iterate through the characters in word, convert them to a lowercase string, then look up their key value in the score dictionary and add them to fscore. But when I run the code I get 0 as the score no matter what. What am I missing?

[EDIT]

I can't delete this post, but I figured out the fix:

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


#2

>>> str(34534535345) # this converts the number to string
'34534535345'

#3

If you want to make your code a little more elegant you could replace:

score[(str(i).lower())]

with:

score[i.lower()]

You do not need to put str() b/c it is iterating through a string.