9.crabble


#1


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

Traceback (most recent call last):
_ File "python", line 19, in _
_ File "python", line 16, in scrabble_score_
NameError: global name 'socre' is not defined

the "score"is of dic.
why should i have define the global name again?
the issue is seen for now ,i am not sure any other issue occur sequently.

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):
    acore=0
    
    for m in word :
        if m not in score:
            m.lower
        acore+=socre[m:]
    return score
        
scrabble_score("sdf")


#2

Just looking at the error message you have, in this line:

acore+=socre[m:]

you misspelled score (seems you swapped the c and o)


#3

Thanks for watching!

this may draw a mistake from audience.
ths "acore "is just a variable which i named for storing the score.
because the word "score " is already taken for the dic.


#4

Forgive a non native english speaker, but did you resolve the issue?

Naming your variable the right way is very important, i wouldn't have called the variable acore, i would have it total_score or points, or something else logical.


#5

i am chinese.
i have to check the basis knowledge of the dic.
i will keep my eye on it until i solve it.


#6

but did you correctly spell score on this line:

acore+=socre[m:]

yes, i know acore is a variable, but socre isn't, it is misspelled, it should be:

acore += score[m:]

#7

oh, i finally ran your code, there seem to be many more problems. This line:

acore += score[m:]

requires another update, it should be score[m], m contains your letter, which mean using brackets notation will get the right value.

You are trying to convert to lowercase here:

m.lower

but lower is a function, so in other to call a function, should be function name + brackets:

m.lower()

now, m becomes lowercase, but it doesn't store this anywhere, you could just store this in m:

m = m.lower()

And finally this line:

return score

i would return the total score (your score variable doesn't contain the total score), now which variable contains the total score?


#8

yes i can run it too.I have so weak basis of the fundamental knowledge.

thank u.