Scrabble Project

Why is it that I`m getting ‘3’ as a result for total points instead of ‘15’?

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)

Have a look at this guide on how to format code in forum posts:

Based on your result of 3 instead of 15, I suspect the mistake lies in placing the return statement inside the loop:

// Your code:
def score_word(word):
    point_total = 0
    for letter in word:
        point_total += letter_to_points.get(letter, 0)
        return point_total

// It should be:
def score_word(word):
    point_total = 0
    for letter in word:
        point_total += letter_to_points.get(letter, 0)
    return point_total
2 Likes

Wow! Thank you for your help!

1 Like