Scrabble_score find an error?


#1



What's wrong with this code? I'm trying to find exactly why this doesn't work?


def scrabble_score(word):
    inp=str(word).lower()
    for i in inp:
        count=0
        vo=len(inp)
        while vo>0:
            count=count+score[i]
            vo-=1


#2

For the exercise scrabble score in Python, there are certain scores for certain numbers, as is provided in the dictionary at the top of the code. You have to use this dictionary to add together the total scrabble score of the word.

Regards,
Barry Allen


#3

@bartholomewallen, pretty sure he has the dictionary, where else does score refers to?

Why do you have two loops? it looks confusing, you just need one to loop over the letters of your word and add the points to count.

I would place count outside the loop in that case, since otherwise you score gets reset each time


#4

I get what you mean.

def scrabble_score(word):
result = 0
for char in word.lower():
result += score[char]
return result
this code works, but I don't get why it considers every letter and then stops while my code takes into account only the first letter?
Thanks btw!


#5

@stetim94, you are very right, of course. And @microcoder01837 you can also replace the while loop with a for loop iterating over the length of inp, instead of having to assign another variable just holding the length.

Regards,
Barry Allen


#6

you want to have points for all your letters? Otherwise you are going to lose this scrabble game, why should it stop after the first letter?


#7

I understand the rules, I'm asking why my original code does not add every letter's point to the count?


#8

@microcoder01837, your original code doesn't take into account every letter's point because you are resetting your count variable in every iteration So the value it returns is just the last letter's scrabble score. Hope this clears things out for you...

Regards,
Barry Allen


#9

It does. I guess I overthink lol. THank you!