Scrabble_score questions


#1



I am not sure why this error message show up:
Oops, try again. Your function fails on scrabble_score("pie"). It returns "90" when it should return "5"


I think the for loop setting is good, can anyone help me to figure out ?


Replace this line with your code. 
def scrabble_score(text):
    score = 0
    for n in text:
        if n == "a" or "A" or "i" or "I" or "l" or "L" or "o" or "O" or "n" or "N" or "s" or "S" or "r" or "R" or "u" or "U" or "t" or "T":
            score = score +1
        if n == "d" or "g" or "D" or "G":
            score = score +2 
        if n == "c" or "C" or "b" or "B" or "m" or "M" or "f" or "F" or "w" or "W" or "v" or "V" or "y" or "Y":
            score = score + 4
        if n == "k" or "K":
            score = score +5
        if n == "j" or "J" or "x" or "X":
            score = score + 8
        if n == "q" or "Q" or "z" or "Z":
            score = score +10
        else: 
            score= score + 0
    return score
    
print scrabble_score("djfklj")


#2

Why are you doing this thing with logical arguments? Before your score- variable, set text to lowercase.

text = text.lower()

After it, add every point that your word got to score.

score += points[n]
    return score

Last but not at least, print your score.


#4

That code is easier if you keep the score dictionary as it is and compare the letters of text with it. try replacing the additional ifs with elif


#5

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