Scrabble 8/15

Hi

Could you please help me understand why my code in task 8/15 results in 3 rather than 15? Please see the link below to the scrabble exercise.

https://www.codecademy.com/courses/learn-python-3/projects/scrabble

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
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")
print(brownie_points) 

Thanks in advance for your help.

Note that return exits a function as soon as it is executed. In your code when does this occur? If you can’t tell, try some print statements or similar.

Hi @tgrtim, thank you so much for your reply. It was such a silly mistake…

Thank you!

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