9. Scrabble Score "Your code threw a “local variable ‘total_score’ referenced before assignment” error."


#1

Here’s my code:

“”"
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):
–total_score == 0 #sets the total score
–word = word.lower() #keeps input cohesive
–for letter in word:
----total_score += score[letter] #Adds word score to the total score
–return total_score #Return total score
""“
Here’s my error:
”"“
Did you create a function called scrabble_score? Your code threw a “local variable ‘total_score’ referenced before assignment” error.
”""


#2

Nope, it returns a boolean because the above is a comparison, not an assignment.


#3

total_score = 0
now it says:
Your function fails on scrabble_score(“pie”). It returns “3” when it should return “5”.
Idk where to go from here


#4

Got it, all I did was move my return total_score back 2 spaces


#5

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