Scrabble_score, 'unicode' object is not callable


#1



scrabble_score

I create this code, and thought it's good to use. But when I running code, shows out
Traceback (most recent call last):
File "python", line 19, in
File "python", line 14, in scrabble_score
TypeError: 'unicode' object is not callable

Hope somebody can help me out.
Thanks.


word = raw_input("Enter a word:")
print word
def scrabble_score(word):
    w = word.lower()
    s = 0
    i = 0
    while i < len(w):
        s += score[w(i)]
        i += 1    
    return s


#2

Hi @datasolver52507 ,

In this line ...

s += score[w(i)]

... w is a string, so the syntax, w(i), appears to be an attempt to call a string as if it were a function.

Perhaps you actually intended to index w instead. What is the proper syntax for doing that?


#3

That's the point. w is a string, I use it as a list.
Thank you for help.


#4

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