# 9. Scrabble Score

#1

in the console
File "python", line 7
scrabble_score(word):
^
SyntaxError: invalid syntax

the error message
Oops, try again. Did you create a function called scrabble_score? Your code threw a "global name 'scrabble_score' is not defined" error.

the total should add up the word but its not

``````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}

scrabble_score(word):
total = 0
for x in word:
for x in "a":
total = total + 1
for x in "b":
total = total + 3
for x in "c":
total = total + 3
for x in "d":
total = total + 2
for x in "e":
total = total + 1
for x in "f":
total = total + 4
for x in "g":
total = total + 2
for x in "h":
total = total + 4
for x in "i":
total = total + 1
for x in "j":
total = total + 8
for x in "k":
total = total + 5
for x in "l":
total = total + 1
for x in "m":
total = total + 3
for x in "n":
total = total + 1
for x in "o":
total = total + 1
for x in "p":
total = total + 3
for x in "q":
total = total + 10
for x in "r":
total = total + 1
for x in "s":
total = total + 1
for x in "t":
total = total + 1
for x in "u":
total = total + 1
for x in "v":
total = total + 4
for x in "w":
total = total + 4
for x in "x":
total = total + 8
for x in "y":
total = total + 4
for x in "z":
total = total + 10

#2
``scrabble_score(word)``

looks like a function call, not a definition.

``def my_function(parameter):``

Not sure I get your logic in using 26 for loops. Is not the main loop sufficient? We are given a look-up dictionary to which we can refer for letter values.

#3

Lol forgot to put def in but now i get this

Oops, try again. Your function fails on scrabble_score("pie"). It returns "261" when it should return "5".

#4

Did you get rid of all those inner loops?

#5

yup i didnt, heres the code.

``````def scrabble_score(word):
total = 0
for x in word:
for x in "a":
total = total + 1
for x in "b":
total = total + 3
for x in "c":
total = total + 3
for x in "d":
total = total + 2
for x in "e":
total = total + 1
for x in "f":
total = total + 4
for x in "g":
total = total + 2
for x in "h":
total = total + 4
for x in "i":
total = total + 1
for x in "j":
total = total + 8
for x in "k":
total = total + 5
for x in "l":
total = total + 1
for x in "m":
total = total + 3
for x in "n":
total = total + 1
for x in "o":
total = total + 1
for x in "p":
total = total + 3
for x in "q":
total = total + 10
for x in "r":
total = total + 1
for x in "s":
total = total + 1
for x in "t":
total = total + 1
for x in "u":
total = total + 1
for x in "v":
total = total + 4
for x in "w":
total = total + 4
for x in "x":
total = total + 8
for x in "y":
total = total + 4
for x in "z":
total = total + 10

#6

What is this supposed to do?

Does it behave like you want? Have you tried testing this part on its own?

And while you should figure that out, also note that computers are really good at repeating things, so your code should not be repeating itself, it should instead tell the computer to do some repeating

#7

So i should remove the outer loop?

#8

I'm not saying anything about how your code should be edited, those are conclusions you have to make yourself.

What I am saying though is that the code I quoted probably doesn't have the effect you want it to have.

So I think you should test that code by itself without anything else, and confirm whether it's doing what you want.

And also you really really need to take note of that the information about how many points each letter is worth is already stored in the `scores` variable, your program should look at that

#9

I dont know what your telling me, stop talking in riddles and get to the point. I wont get anything from this.

#10

That makes two of us, now, to whom some explanation is due as to why you have all those inner loops? The error message clearly indicates it is not working. How much have you throught this through?

#12

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