Scrabble_score


#1

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

ERROR(After giving input, no syntax errors before that):
Traceback (most recent call last):
File “python”, line 15, in
File “python”, line 11, in scrabble_score
KeyError: (0, u’a’)

Expected Result:
Code to return the scrabble score successfully.


My code:
def scrabble_score(word):
  word = word.lower()
  word_score = 0
  for item in enumerate(word):
    word_score += score[item]
  return word_score

word = raw_input("Enter your word: ")
print "Your score is: " + str(scrabble_score(word))

Can anyone figure out where I am going wrong?


#2

enumerate produces a tuple, which gives you both index and value from the string, so you need two variable, one for the index and one for the value, run this code to see:

x = "example"
for index, item in enumerate(x):
    print index, item

personally, why would you use enumerate here? Dictionaries are accessed by key (which is the item), the index is absolutely not used, so we don’t need the index, so we don’t need enumerate, given there are easier ways to just get values from a string using a for loop


#4