Scrabble_score


#1



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


My code is giving the error: Your function fails on scrabble_score("pie"). It returns "0" when it should return "5".
I do not know what is wrong, please help me.


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}

def scrabble_score(word):
    word = raw_input()
    word = word.lower()
    result = 0
    for letter in word:
        if letter in ['a', 'e', 'i', 'o', 'n', 's', 'r', 'u', 't']:
            result += 1
        elif letter in ['d', 'g']:
            result += 2
        elif letter in ['c', 'b', 'm', 'p']:
            result += 3
        elif letter in ['f', 'h', 'w', 'v', 'y']:
            result += 4
        elif letter in ['k']:
            result += 5
        elif letter in ['j', 'x']:
            result += 8
        elif letter in ['z', 'q']:
            result += 10
        else:
            result += 10
    return result
    print result


#2

Hi @trains_are_love_trai,

The letter 'l' is missing from your loop. However, you are doing it the hard way. Instead of including the conditional if, elif, and else blocks, use the score dictionary to look up the value associated with each character in word.

Also, remove this from the function ...

    word = raw_input()

#3

Thank you removing word = raw.input() and adding the letter 'l' worked.
Thank you for telling me how to do it the easier way as well :slight_smile:


#4