Scrabble_Score error


I am stuck at Unit 8 exercise 9 Scrabble Score

I am writing the following line of code:

def scrabble_score(word):
word = word.lower()
total = 0
for i in word:
total = word[i].sum()
return total

This is the error:

 Oops, try again.
Does your scrabble_score function take exactly one argument (a

string)? Your code threw a "string indices must be integers, not str"

What all am I doing wrong? How dictionary needs to be treated?




You may try this:
total = 0
for i in word:
total += score[i]
return total

score is the dictionary provided, score[i] picks the corresponding score of a letter


oh ok , I think .sum works on lists and dataframes... is that right?



Here's what I did:

def scrabble_score(word):
word = word.lower()
totalScore = 0
for c in word:
totalScore += score[c]
return totalScore

print scrabble_score("etiboy")


You're just trying to sum index of the input word.
Here is a correct solution:

def scrabble_score(word):
--total = 0
--for letter in word.lower():
-------for key,value in score.items():
-------------if letter == key:
-------------------total += value
** return total**

Enjoy!!! :slight_smile:


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