9. Scrabble score - help to print end score from raw input


#1



I am stuck on exercise 9 of Practice Makes Perfect, scrabble_score.

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 'Pick a word?', 
word = raw_input()
def scrabble_score(word):
    end_score = 0
    for char in word.lower():
        end_score = end_score + score[char]
    return end_score
print end_score


With the bottom 'print' line, i get:
Oops, try again. Your code looks a bit off--it threw a "name 'end_score' is not defined" error.
And in the raw_input box:
Traceback (most recent call last):
File "python", line 14, in
NameError: name 'end_score' is not defined

I want to be able to see the final score (end_score), but when I remove the last print line the exercise just says "Way to go! Next Lesson" without actually showing me the score. How else can I do this without using print?


#2

What line raised the exception?


#5

The last line - print end_score
Does it have the wrong indentation?


#6

No, but it should be a call to the function. That variable is not visible outside of the function.

print scrabble_score(word)

will print the return value from the function.


#7

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