What is wrong with my code and explain why?


#1

what is wrong with my code, it only returns 3

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):
for chars in word:
user_char = chars # contains the letters and words
for i in score:
chars = i # each alphabet in the scarbble Broad
points = score[i] # each point assigned to each alpha
result = 0 # adds up the total from the alpha
for c in chars:
if c == user_char:
result = result + points
return result


#2

@warm_tacos,
Knowing that you can access the score =dictionary=
using for instance score["u"] you would get the VALUE 1

In your scrabble_score function
you want to initialize a variable total to 0

Then with a FOR-IN loop you will loop over the word character by character,
and at every iteration you will get the associated VALUE from the dictionary,
and it is with this VALUE you increment the total variable

at the end you will return this total