9/15 Code does not work on last input


#1

I dont understand why it has stuck at the last input.
“Your function fails on scrabble_score(“DuNe”). It returns “2” when it should return “5”.”

def scrabble_score(word):
word.lower()
my_list = []
total = 0

for letter in word:
my_list.append(letter)

for letter in my_list:
for point in score:
if letter == point:
total += score[point]

return total
print total


#2

oh okay i solved it.
forgot to assign the word to word.lower()


#3

The letter scores is a lookup list, which for our purposes contains all we need assuming valid word characters are passed to the function. We do not need to iterate the dictionary, only the word (which is iterable so no list required, either).

def scrabble_score(word):
    total = 0
    for letter in word.lower():
        total += score[letter]
    return total

#4

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