9. scrabble_score


I realise I can include the word.lower() inside the function, which of course is accepted, but I thought I'd address the lower-case requirement immediately at input. Is there any reason not to do it my way below? Because it gives me this error

Oops, try again. Remember to make your function work for upper- and lowercase letters!


score = {"a": 1, "c": 3, "b": 3, "e": 1, "d": 2, "g": 2, 
         "f": 4, "i": 1, "h": 4, "k": 5, "j": 8, "m": 3, 
         "l": 1, "o": 1, "n": 1, "q": 10, "p": 3, "s": 1, 
         "r": 1, "u": 1, "t": 1, "w": 4, "v": 4, "y": 4, 
         "x": 8, "z": 10}
word = raw_input("Enter your word: ").lower()
print word

def scrabble_score(word):
    total = 0
    for letter in word:
        if letter.isalpha() == False:
            print "That's not a word, dummy. Try again."
            total += score[letter]
            print str(letter) + ": " + str(score[letter])
        return total

print "Total score of %s is: " % (word) + str(scrabble_score(word)).


Hi @lickwid,

You can do it in both places. It is a better function if its policy is to score both cases correctly.

Codecademy tests your function independently of how you process the user's input prior to calling the function.


You should not do this, it's very redundant to test if something is one or the other boolean value, because the result of doing so is a boolean.

What that looks like in my eyes is:

if letter.isalpha() == False == True == True == True == True == True:

And you'd say I'm being silly, but if you remove them all then that includes the False, because why should that one remain?

Instead that should be written as:

if not letter.isalpha():


Great thank you. The instructions do say to ensure the function can handle both, I was just making sure I wouldn't come across any issues if I used this method in future to immediately receive a lower-case input rather than an extra line to convert it.

I considered this actually, then but thought it wouldn't matter either way. Thanks for pointing that out. Just so I understand correctly, IF string.isalpha() already checks if that is True, so there's no need for another comparison? (I imagine this as "If the red train is red, then is the train red?"). Does this apply to all dot notation methods I'm bound to come across or just certain ones?


It applies to expressions, in general, that evaluate to True or False, rather than only to ones that involve method calls.

You could provide the following advice, regarding venturing out into wet weather ...

If it is raining, bring an umbrella.

You could advise this, instead, but that would be redundant ...

If it is true that it is raining, bring an umbrella.

Admittedly, there is a shade of difference in the tone of the two statements, but taken literally, they convey equivalent information.


Nicely. Thanks :smile:


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