Scrabble_score


#1

https://www.codecademy.com/courses/learn-python/lessons/practice-makes-perfect/exercises/scrabblescore?action=lesson_resume

I get the following error message:
“Traceback (most recent call last):
File “python”, line 16, in
File “python”, line 11, in scrabble_score
TypeError: ‘int’ object is not iterable”

I have tried different ways to complete this exercise, but this is the closest I can get to a solution. I don’t understand the errors I get though. Could someone help me?



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 p in word:
    for n in total:
      if p == n:
        total = total + score[n]
  return total
  
print scrabble_score("cliffhanger")



#2

total is not an iterable.

For this exercise assume that the input is in fact a word containing only alpha characters. That means only one loop and no conditional.


#3

Oh… God dang it. I have spent almost 2 hours on this, I must be a bit tired. Thanks a lot @mtf


#4

I fixed it btw. Thanks


#5

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