Scrabble_score


#1

c any one help to solve this problem?


#2

i'm a bit miffed about this one. my function works but keeps saying:
"Oops, try again. Your function fails on scrabble_score("pie"). It returns "None" when it should return "5"."

hchirasani - check you FOR statement. it needs to iterate through WORD.
you are then checking to see if S appears IN SCORE
then you are adding the VALUE that it finds IN SCORE to TOTAL
TOTAL = TOTAL + SCORE[S]

hope this help


#3

No, its not getting. It was showing same error.


#4

for s in str(word):

word is already a string so needs no conversion.

for s in word:

We can help the reader by using a descriptive variable:

for letter in word:

or

for char in word:

There is no need to write an if statement. We are only iterating over the letters in the word and looking them up in the score table.

    result += score[letter]

#6

i had changed my program but i got this error. could you tell me where my program went wrong?


#7

You have defined and initialized a total variable so should be accumulating on that one, not result, which is undefined.


#8

for this what i have to do?


#9

Moving right along. Great! If we examine the lookup table (dictionary) we see that all the keys are lowercase. That means we should be submitting only lowercase lookups. However, it does not suggest that we manipulate the function inputs which we should be able to leave intact.

We can manipulate an expression using the input without changing the input.

# no need to convert so drop the str() function.

for letter in word.lower():

will work on all manner of inputs without changing them. It's the outcome of the expression that is cached for this loop.


#10

This is my program. Is there any wrong in it.


#11

Not that I can see. Your session may be timed out. Copy the code so you have it on the clipboard, then refresh the page. If the code is still there (it should be) then Submit.

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

>>> scrabble_score("pie")
5
>>> scrabble_score("PIE")
5
>>>

#12

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