9. scrabble_score. I think I found a BUG ))


Here is my code. it works properly, but I couldn't do next step ((


Can't really test it without having the code (text, not picture)

Something else to note though, is that you're comparing ALL keys in a dictionary to the one you're after. Is that how you would find something in a language dictionary/phone book? (disregarding that the physical versions are nearly obsolete).. and worse yet is that when you've found a match you look it up by key anyway!


Here's the code. Now it works

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):
    total = 0
    print word
    for letter_word in word.lower():
        for letter_score in score:
            if letter_word == letter_score:
                total += score[letter_word]
    return total
print scrabble_score(raw_input("Put some words: "))


I think it is wrong because you have to .lower() the word before doing the rest


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