Scrabble_Score error


#1

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"
error.

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

Thanks


#2

Hi,

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


#3

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

Thanks


#4

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")


#5

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:


#6

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