Scrabble_score

#1

It seems like my first for loop only goes through one iteration.
Here is the error message:

Your function fails on scrabble_score("DuNe"). It returns "2" when it should return "5".

What edits can be done to my code so that it goes through the rest of the word?
Thanks!

``````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):
total = 0
for i in word:
i.lower()
for x in score:
if i == x:
total += score[x]

#2

Every thing is good up to and through
for i in word:

You are saying "for every iteration of each letter in the word "

you want to tally up the score of each letter.

You are using the letter i so:

total += score[i]. Make that small change and get rid of the extra three lines of code

#3

i disagree, the learner loops through the dictionary so that points are only added if the letter is in the dictionary? Even though the exercise doesn't ask for it, its perfectly fine to build, now his function can handle invalid input

@fviramontes, here:

`` i.lower()``

you convert to lowercase, but you don't store the lowercase letter anywhere

#4

I was thinking along these lines:

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()
points = 0
for c in word:
points += score[c]
return points
print scrabble_score("quizzers")

#5

i know, but i tried to stay as close to fviramontes code as possible. That is easiest for him

#6

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