<scrabble_score()> my code works well but


#1



https://www.codecademy.com/courses/python-intermediate-en-rCQKw/1/3?curriculum_id=4f89dab3d788890003000096


Here is my error message:

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


But, when i submit

scrabble_score("pie")

on prompt on my own, it gives the right answer "5" ,not "None"!
and it works well on another words like "Amen","codeacademy","turtle",etc....

So I guess my code works well without any bugs, according to the instructions.
But I cant still go through this page because of the error message.

Is there anybody to give me advice?thanks!


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):
    n=0
    lower_word=word.lower()
    for i in lower_word:
        n += score[i]
    print n


#2

Hi @juwankim,

You have ...

    print n

Instead, you need to have ...

    return n

print merely displays the value of an expression or series of expressions. A return statement in a function makes a value available for possible further use by a program, and that's what you need to do here.


#3

OMG thanks!!!!!!! It works properly after change my code according to your advice.
Guess I need to study more about the difference of 'print' and 'return'
THANKS A LOT for your help!:slight_smile:


#4