Scrabble_score


#1

I wrote this solution, which almost works… I think the only problem is that it doesn’t register letters that occur more than once in a word. Does anyone know how to adjust this? Thanks!


#2

That is a lot of code for such a simple look-up problem. We are given a letter lookup table with values for each letter, and a word for which to compute and return the score. Since there are no constraints, this will work for any word.

For example…

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

#3

Yeah, I know that there are easier solutions like yours, but I was just wondering since I tried it this way how I could solve the problem so that I can learn something from my own unelegant solution :stuck_out_tongue:


#4

A few things to consider. You don’t need to respond unless you feel the need to, this is entirely designed to make you think through what you’re doing and find where you’re going wrong.




Your code does at some point process each letter’s score What would you need to do with that? Addition, right? And then you’re done. You’re doing something else first. Can you argue for why that’s useful?

That something is also broken like you point out. My argument is that it should be cut out entirely, a conclusion I think you’ll reach too, even when following your own idea - because your idea probably isn’t that.

As for the broken part, you’re using a dictionary, and doing some operations. What is it that you wanted the dictionary do for you (did you think that through?) and what is your argument for that it supports those operations?


You might generally want to argue for why anything you ever write is necessary. If it’s not, it probably shouldn’t be there. Never assume something is required. Cut it out.


#5

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