Passed, but Code Produces an Error


#1

When I enter the following code:

def scrabble_score(word):
total = 0
word = word.lower()
for character in word:
total += score[character]
return total

and hit Run, I receive a green tick in the box.

However, when I type:

print scrabble_score(Python)

below, I receive an error message. Is there something I’m doing wrong in trying to print it, or is Codecademy mistakenly saying my code is correct when in fact it isn’t?


How can I access a dictionary key value inside of a loop?
#2

yep, there is. So you already seemed to have identified the source of the problem.

Python is a undefined variable, shouldn’t it be a string?


#3

Hello!
Need help…
I wrote this code:

def scrabble_score(word):
total = 0
word = word.lower()
for w in word:
for m in score:
if w == m:
total = total + score[m]
return total
print total

scrabble_score(“text”)

But it doesn’t show an result at all… What is wrong?


#4

the print statement is never reached, given return keyword will end the function. But you should just print the returned result by putting the print statement before the function call


#5

Could you, please, write the example?


#6

Why? You need to be able to understand what needs changing, if i write the example you will never make this step.

So please ask specific points about my instructions you do not understand, and come forward with ideas


#7

def scrabble_score(word):
total = 0
word = word.lower()
for w in word:
for m in score:
if w == m:
total = total + score[m]
return total

print scrabble_score(“text”)

This one is correct variant, right?


#8

looks right, but more importantly do you understand it?


#9

I think I do, thanks! And it actually works correctly.