9. scrabble_score (our function fails on scrabble_score("pie"). It returns "3" when it should return "5")



Oops, try again. Your function fails on scrabble_score("pie"). It returns "3" when it should return "5".

I still can't really understand why it prints out 3 instead of 5. Perhaps, there could be something wrong with my return statement?

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}
print "Put a word:"
word = raw_input()
def scrabble_score(word):
    word = word.lower()
    total = 0
    for letter_word in word.lower():
        for letter_score in score:
            if letter_word == letter_score:
                total = total + score[letter_word]
                return total  
print scrabble_score(word)


by default, at the end of a function a function returns None. If we want to return something else, we can use the return keyword

This means, that when return is reached, the function ends. If the function is in a loop, the loop simply breaks.

With this knowledge, what do you think you need to change?


You are making it quite complicated for yourself. For example you don't use your word variable in you loop since you do the for loop on "word.lower()". You dont need your if statement because you know all the letters in the alphabet is in the dict


I changed the location of my return statement and it worked for me ( thank you so much for your advice!), but for some reason it looks weird to me. Could you tell me if what I did is right or not?


in this regard, @methodjumper11748 is right, your code is quit complicated.

The exercise assumes only valid input, if this is the case, you can make your code a lot easier


I am not able to understand what i am doing wrong here


Never mind. it works now. I went out of the course screen and came back and it was fixed.


before your "return" you should del three Tab