9. scrabble_score

"Oops, try again. Remember to make your function work for upper- and lowercase letters!"

I think everything else is correct, but I don't understand why word.lower() isn't changing anything. I've played around with the location of it a bit or changing it to letters.lower() inside the for loop and nothing changes.

def scrabble_score(word):
    total = 0
    for letters in word:
        total += score[letters]
    print score
    return score


lower is not an in-place method. It needs to be re-assigned.

word = word.lower()


def scrabble_score(word):
    word= word.lower()
    total = 0
    i = len(word)-1
    while i>0:
        total += score[word[i]]
    return total

What's wrong?


I found a way how your code works:

word = str(raw_input('Enter a word: '))

def scrabble_score(word):
word= word.lower()
total = 0
i = len(word)
while i>0:
total += score[word[i-1]]
return total
print scrabble_score(word)

but I do not really have an answer why :-/ my guess is that the subtruction by one has to be within the while-loop... would be great if someone could explain?


Ah, thanks! It worked. But I have previously tried putting -1 outside the loop and it has worked.
I too would like to get to know why it didn't work this time.


while loops are handy when we do not have determined bounds, but in this exercise the bounds are fixed, so a for loop would be more meaningful.

for letter in word:
    total += score[letter]
return total


Thank you for your help man


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