Scrabble_score error '0' why?


Your code looks a bit off–it threw a “0” error. Check the Hint if you need help!

I expected to have my result in the (end) variable I tried everything

def scrabble_score(word):
  for i in range(0,lenk):
    if word1[i]==score[i]:
  return end 


No need to set up a conditional. Just query the lookup table.

end += score[i]

Not sure I like the choice of variable name. It does not reflect its true meaning. total would be more to the point. Truthfulness and meaningfulness are the two most important aspects of a variable name.


I put the conditional for the program to be sure for no other character but the problem is still there I get the same error

def scrabble_score(word):
for i in range(0,lenk):
return total


The range() function excludes the last index.

for i in range(len(word)):

Your code is omitting the last letter in the word.

total += score[word[i]]

Another simpler way would be to loop over the word directly…

for letter in word:
    total += score[letter]

Sorry for the misinformation, earlier.


Thank you for your reply but if you can help me to understand please. The code was correct and run with total += score[ word[i] ] and didn’t run with total += score[ i ] why is that. I appreciate the information about the range()I thought that it didn’t excludes the last index.


When we iterate over a range, we are working with the index. When we iterate over an iterable (string, list, dictionary, tuple, set) we are working with the value.

for i in range(len(word)):

gives us an index which we must apply to word to get the value (letter) stored there.

for letter in word:

gives us a letter in the word.


ok thank you very much.


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