How do I print the below Scrabble score code


#1

How do i print the below code?
link: https://www.codecademy.com/courses/learn-python/lessons/practice-makes-perfect/exercises/scrabblescore?action=resume_content_item

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):
  word = word.lower()
  total = 0
  for letter in word:
    for leter in score:
      if letter == leter:
        total = total + score[leter]
  return total

#2

functions only execute when called, so you could call the function?


#3

In other words, print the function call.

def foo(bar):
    return bar

print (foo('bar'))    # bar

#4

I tried calling it, but just prints out an error. Maybe you can check my code and tell me where I went wrong?

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):
word = word.lower()
total = 0
for letter in word:
for leter in score:
if letter == leter:
total = total + score[leter]
return total

print scrabble_score(score)

See below error:

Traceback (most recent call last): File “python”, line 16, in <module> File “python”, line 8, in scrabble_score AttributeError: ‘dict’ object has no attribute ‘lower’


#5

the function call, why score as an argument?

the parameters expects a word (of type string) as argument. You want to get the score of a word. That is the purpose of the function

the score dictionary is to from letter to points, you use it in the function.


#6

I am trying to call the dictionary score with print scrable_score(score)


#7

same question as i asked before, why?


#8

trying to calculate the total of all the letters or get the sum of all the letters in the scrable game
do you know of a better code as per the dict above


#9

i don’t think that is how the function is intended to be used. The function expects a string argument, so this can be a word the user entered/played:

print scrabble_score("hello")