Wrong scores expected in Scrabble Project

Hi everyone,

I need some help with this project https://www.codecademy.com/courses/learn-python-3/projects/scrabble

Somehow I get the following scores, which do not match the solutions. I can’t find the error. Can someone please help?

Here is my code:

player_to_words = {“player1”: [“BLUE”, “TENNIS”, “EXIT”], “wordNerd”: [“EARTH”, “EYES”, “MACHINE”], “Lexy Con”: [“ERASER”, “BELLY”, “HUSKY”], “Prof Reader”: [“ZAP”, “COMA”, “PERIOD”]}
player_to_points = {}
for player, words in player_to_words.items():
player_points = 0
for word in words:
player_points = score_word(word)
player_to_points[player] = player_points
print(player_to_points)

My result: {‘player1’: 11, ‘wordNerd’: 17, ‘Lexy Con’: 15, ‘Prof Reader’: 9}
Expected result: {‘player1’: 36, ‘wordNerd’: 32, ‘Lexy Con’: 31, ‘Prof Reader’: 31}

What did I do wrong? :woozy_face:

Thanks a lot in advance, I really appreciate your help!

Should that be accumulating? Written as an assignment you only get the last word score.

print (score_word('EXIT'))    #  11

Yes, they should be accumulated. I couldn’t find any indentation error…I just realized a made a mistake when writing player1’s correct score: it should be 29, not 36!

So we can assume you corrected that line? +=

From your posted code we cannot tell where the indentation is. To format code block samples, enclose the entire thing with three back ticks before and after, on their own line.

Like so,

```python
# code here
```
1 Like

Hi!

Here’s my entire code with indentation:

letter_to_points = {key:value for key,value in zip(letters, points)}
letter_to_points[""] = 0
print(letter_to_points)
def score_word(word):
  point_total = 0
  for letter in word:
    point_total += letter_to_points.get(letter, 0)
  return point_total
brownie_points = score_word("BROWNIE")
player_to_words = {"player1": ["BLUE", "TENNIS", "EXIT"], "wordNerd": ["EARTH", "EYES", "MACHINE"], "Lexy Con": ["ERASER", "BELLY", "HUSKY"], "Prof Reader": ["ZAP", "COMA", "PERIOD"]}
player_to_points = {}
for player, words in player_to_words.items():
  player_points = 0
  for word in words:
    player_points = score_word(word)   
  player_to_points[player] = player_points
print(player_to_points)

I’m not sure what I should correct about the line with += …would you mind giving me another hint?
Thanks a lot for your help!

That line is not accumulating player_points the way it should.

Ohh I finally see now! It is player_points += score_word(word)
Thanks Roy!

1 Like

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