Scrabble_score


#1



I'm getting a Error: score of 23 instead of 24 for "xenophobia"

I should get score of 24.
Can anybody tell me what I'm doing wrong please?


def scrabble_score(word):
    
    word_lower = word.lower()
    print word_lower
    player_score = 0
    for i in score:
        if i in word_lower:
            player_score+=score[i]
            
            
    return player_score
        
print scrabble_score("xenophobia")


#2

Just realized that this code doesn't like duplicated elements.

For example.
xenophobia contains 2 "o" . The second "o" doesn't get added up

Is there anything I should do with the for loop?


#3

Assuming valid inputs (letter case aside) is it necessary to use an if statement?


#5

Definitely not...

All good now. Thanks very much mtf

def scrabble_score(word):

word_lower = word.lower()
print word_lower
player_score = 0
for i in word_lower:
    player_score+=score[i]

return player_score

print scrabble_score("xenophobia")


#6

Given that word is a value, it is only a copy of the passed in argument so we can change it directly, without the need of a new variable.

word = word.lower()

I'm guessing the print statement is for debugging purposes. It can (should) be removed.


#7

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