Scrabble Score


#1

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
    word.lower()
    for letter in word:
        for m in score:
            if letter==score:
                total = score[letter] + total
    return total

I do not understand what's going wrong in this one. Please help.


#2

Two mistakes here.

The first one is here:

    word.lower()
    for letter in word:

Think about what you haven't done with the word variable. Put some print statements in for word before and after word.lower() - make the input to scrabble_score() have caps in it.

The second is here:

for m in score:
            if letter==score:

Have a think about what you are testing letter against.
If you need more detail just ask.


#3

The following code worked out for me:

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):
w1=str(word) #Converting into string
w=w1.lower() #Conerting into lowercase
sum=0
for i in w: #Looping through entered word
for n in score: #Looping through score
if i==n:
sum=sum+score[n]

return sum

#4

You have the right idea, you just actually went one step too far. You don't need to use a second for loop in this problem. In fact, if you just delete the two lines after your first for loop statement leaving the total = score[letter] + total behind your code should word perfectly.


#5

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