Python 3 Scrabble project: loop only loops through the first letter of my values

Hello everyone,
I’ve tried several times to get the right answer. I keep getting

{'player1': 5, 'wordNerd': 5, 'Lexi Con': 8, 'Prof Reader': 16} 

It seems that my nested loop is only going through the first letter in the lists of values. I’m not sure why. I checked my code against the video on youtube and I still can’t seem to find the issue.

here is my code

letters = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]

points = [1, 3, 3, 2, 1, 4, 2, 4, 1, 8, 5, 1, 3, 4, 1, 3, 10, 1, 1, 1, 1, 4, 4, 8, 4, 10]

letter_to_points = {

  key: value 

  for key, value 

  in zip(letters, points)}

letter_to_points[" "] = 0


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 = {


  "wordNerd": ["EARTH", "EYES", "MACHINE"],

  "Lexi 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


return point_total is inside your loop. When a return keyword is reached, the value is hand back to the caller/function call, which signals that the function is done executing. So the remaining loop iterations are not executed


Thank you so much! One little indentation!

Indention, but could just as easy have been a comma or a bracket. Welcome to the life of software developer :stuck_out_tongue:

Oh indention? I’ve never heard of the word. And I just looked it up and apparently both can be used. Not sure why but, english.
Thanks man! haha It actually was fun as frustrating as it was. Like a puzzle

1 Like