Why does my code not return the total?



Basically my code does not give me back the score even if I print it. I get None.

What is the problem that needs to be fixed in order for the code to work and return the total?

def scrabble_score(word):
    word = word.lower()
    total= 0
    for w in word:
    return letters
    for letter in letters:
        for s in score:
            if s == letter:
            total += score[s]
    return total


Don't complicate it, just keep it as simple as possible.

def scrabble_score(word):
(4 spaces) total = 0
(4 spaces) for i in word:
(4 spaces)(4 spaces) total = total+score[i.lower()]
(4 spaces) return total
print scrabble_score("Word")


Two problems there,

This line..
return letters (Get rid of it?)
You're not getting None (It's probably due to CC interpreter), You're getting a list with word's letter separated.
It's due to early introduction of return statement.
return statement makes your function halt at mid of the code, as by nature.

Point 2.
Now in second part,You're using two loops, You can shorten it by just looping over your letters list and adding the corresponding value by using list ( letters list) item as key of score.

for s in letters:


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