Practice makes perfect: Scrabble_Score


#1

My Code Is Below:

 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):
      word = word.lower()
      total = 0
      for i in word:
           total += i
      return total

It says this:

Oops, try again. Does your scrabble_score function take exactly one argument (a string)? Your code threw a "unsupported operand type(s) for +=: 'int' and 'str'" error.

Whats wrong?


#2

You are trying to add a character to total. What you're doing:

for i in word:
#Let's pretend that word is "Hi"
    total += i
#You are then adding H to 0, What is (H + 0)? An Error

#3

thx for reply do you know how I can fix it?


#4

you just need access the value in the dictionary using the key letter: dictionary[key]
and add that to the total

why is this the funniest thing I've seen all day