Scrabble score not adding properly


Hello again,

So I've tried doing the scrabble challenge and I want to know why my bit of code isn't working. I'm aware that dictionaries are unordered so I've added in a list that will allow me to tackle this problem. That said, I've either made this too complicated or in my really complex bit of code I've completely missed something.


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}

x=["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"]

def scrabble_score(word):
for i in word:
while i==x[j]:
return totalscore
return sum(totalscore)

print scrabble_score("pie")


Do you need two loops to iterate through one word?
How many return statements do you need? When should you return?

Take care to get the formatting right when you post code, it gets difficult to discuss code when you posted something that's similar but not the same!


Well that's what I was thinking but I feel that it may not be working because of that

And darn, thought all the spaces were there! :stuck_out_tongue: Is there an easy way of copying over code without losing the formatting?


Yeah, you are overthinking it a lot. I'm actually not really sure what you are even trying to do, so I don't have anything constructive to say about your code, but something as simple as this does the job:

def scrabble_score(word):
    total = 0
    for c in word:
    return total

It's still missing a line or two that protects you from getting exceptions thrown in your face in a special case (Look at the description, hint hint)


I am actually a donut, thank for you this! I think I made it so complex that I needed a new perspective. Just one of those days!