Scrabble_score reciving more input than the error notes


#1

I originally had this set-up but after getting the error
“Your function fails on scrabble_score(“pie”). It returns “None” when it should return “5”.”

I printed out the result to see really what was being inputed to the method which is:

t
e
s
t
a
b
c
p
i
e

My code is here:

def scrabble_score(word):
counter = 0
for i in word.lower():
if i in score:
print i

Why am I getting more than pie?


Why is my code generating "c b a ! n o h t y P", i havent used lists in my program
#2

codecademy needs to validate your code works correctly, this is done by calling the function. So inserting print statements might show function calls codecademy is executing on your function


#3

This will mess up the calculation though if random text is entered.

When doing print score[i]

I get this which is testabcpie:
1
1
1
1
1
3
3
3
1
1


#4

no, why would that mess up the calculation? That is the beauty of functions, you can call the function multiple times with different arguments to calculates scores for different words


#5

I was able to pass simple by doing
counter +=score[i]
return counter

But it really is confusing when de-bugging because the error notes
Your function fails on scrabble_score(“pie”). It returns “None” when it should return “5
but in reality "testabcpie"was entered and not just “pie”


#6

not really, it where 3 separate function calls:

print scrabble_score("test")
print scrabble_score("abc")
print scrabble_score("pie")

None is the default returned value, functions always return, even when you don’t explicitly use a return keyword


#7

So the website is essentially doing three function calls, omitting the first two results and then checking for accuracy on the third item entered “pie”.

It is understandable but certainty makes it kind of confusing when debugging.


#8

i have no idea of the order, pie might also be first. My point was just that it wasn’t a single function call like you thought

or you use it to your advantage, because now you don’t have to add the function calls yourself to see print statement inside the function in action.


#9

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