# Scrabble_score (what am I missing?)

#1

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

So I tried this in IDLE 3 on my computer and it works fine, but for some reason the parser here does not think so? Totally racking my mind, I stepped away from this course for months hoping when I came back with a fresh perspective I could make it work.
Ignore the print lines commented out, this is my bootleg way of debugging in IDLE, Lol

``````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):
#turn word into a list so that it can be iterated
lwr = list(word.lower())
#print(type(lwr),lwr)
#to track score
total = 0
#length of word
j = len(lwr)
#print(j)
for i in lwr:
#print(i)
while i in score and j > 0:
j -= 1
#print('iter #',j)
i = word[j]
#print('letter {} is worth {}'.format(i,score[i]))
total += score[i]
#print('score total is now',total)

#word = input("Enter a word to get the scrabble score > ")
#print('Your score for %s is %d' % (word, scrabble_score(word)))``````

Of course if you comment in the print statements and last two lines you will see it works in IDLE 3.
But not in CA... What am I missing?

#2

The above dictionary is a look-up table. In order to receive credit for multiple instances of a letter in the input we iterate over the word, not the table.

``````word = word.lower()
s = 0
for letter in word:
s += score[letter]
return s``````

or

``return sum([score[x] for x in word.lower()])``

#3

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