c any one help to solve this problem?
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
No, its not getting. It was showing same error.
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:
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]
You have defined and initialized a
total variable so should be accumulating on that one, not
result, which is undefined.
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.
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 >>>
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.