Scrabble_score error


#1



i don't understand why it keeps telling me error, when it computes normally


Replace this line with your code. 
def scrabble_score(word):
    total = 0
    for i in range(len(word)):
        if word[i] in score:
            print word[i], score[word[i]]
            total = total + score[word[i]]
    return total


#2

Does it only say

error

Or does it also say what the problem is? If so, have you considered what it was saying? Was there a problem understanding what it was saying? What was it saying?


#3

"Oops, try again. Your function fails on scrabble_score("DuNe"). It returns "2" when it should return '5' ".

the console prints this although when i call scrabble_score on "DuNe" it shows 5


#4

Sounds like you did something wrong when testing your code. Here's with the score table and an extra line to call your function and print the result:

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 range(len(word)):
        if word[i] in score:
            print word[i], score[word[i]]
            total = total + score[word[i]]
    return total


print 'returned value: {!r}'.format(scrabble_score("DuNe"))

output:

u 1
e 1
returned value: 2

As you see, 2 was indeed the return value. Your own print also shows how it got that result.


#5

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