Scrabble_score


#1



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):
    word.lower()
    total = 0
    for letters in word:
        total += score[letters]
    print score
    return score


#2

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

word = word.lower()

#5

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

What's wrong?


#6

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]]
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?


#7

@stock.lin
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.


#8

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

#9

Thank you for your help man


#10

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