Why isn't my code running correctly? Scrabble_score


#1

Can someone please explain why my code doesn't work.
def scrabble_score(word):
word = word.lower()
total = 0
for letter in word:
total += score[letter]
return total
print scrabble_score("xylophone")

It only returns the value of the first letter. I thought for loops translated as: for EACH blank in blank, then do this... If that is the way they are supposed to work than why does my code only return the value of the first letter?


#2

if that is happening then the best guess is you have your return value inside the for loop. indent that line 4 spaces back(i.e move it out of the for loop)


#3

Thank you!!! It worked.