Scrabble scrabbled


#1



what does this mean please????

Oops, try again. Does your scrabble_score function take exactly one argument (a string)? Your code threw a "'builtin_function_or_method' object is not iterable" error.

why also when I can get it to run does it fail with pie =0 expecting 5, when its supposed to score user input?

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):
# make word low case 
    word = str(raw_input("Enter word: "));
    word = word.lower
    total = 0
    for char in word:
        total+=score[char]
        return total


#2

.lower() is method call, it requires parentheses

if you want to prompt the user for input, do this outside/after the function and supply the user input as argument when calling the function

a function ends the moment a return keyword is reached, if a return keyword is reached in a loop, the loop will break, so your loop breaks in its first iteration, is this what you want?

If you need more help, post an updated version of your code


#3

ok
I think I got that.
its running now but returns error of:

Oops, try again. Your function fails on scrabble_score("pie"). It returns "3" when it should return "5".

So where does the "pie" come from.

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 = str(raw_input("Enter word: "));

def scrabble_score(word):
    word = word.lower();# make word low case 
 
    total = 0
    for char in word:
        total+=score[char]
        return total

#4

i already covered what is causing this error message

the exercise is testing different strings to see your function works correctly, so pie comes from the exercise validition


#5

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}
Ah, so its just a matter of the correct indents before the return.

works now - many thanks.

        
word = raw_input('please enter a word:')

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

print scrabble_score(word)

#6

well, indention just determine how your program behaves, its pretty important


#7

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