9.scrabble_score


#1



https://www.codecademy.com/courses/python-intermediate-en-rCQKw/1/3?curriculum_id=4f89dab3d788890003000096#

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


what's wrong with my code ?


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


#2

Unindent your return statement so that it lines up with your for loop.


#3

so obvious mistake I barely check it out. thanks a lot !


#4

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

Hello,
I wrote this and it didn't work. After seeing this i realize that I needed brackets around the i. I was wondering what the [i] does that the (i) doesn't do. I thought it was a string, and not a list. Forgive me its a nudie question. I have only been studying this for a week or so.

Thanks


#5

That's totally okay and it's not

as you put it. Better to know now than never figuring it out. If you remember, this:

score[i]

Is the way we access a specific element from a dictionary. So what you code is supposed to do is take the score of the specific letter and add it to the total through your for loop. It's important to do that in brackets becuase it means something else entirely in parentheses.


#6

Thank you for clearing that up for me.


#7

Welcome, if you forgot how to access using key I suggest reviewing previous topics again. :slight_smile:


#8

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