# PROBLEM
#
# The first step is to implement some code that allows us to calculate a score 
# for a single word. The function getWordScore should accept as input a string 
# of lowercase letters (a word) and return the integer score of that word, 
# using the game's scoring rules.
#
# You may assume that the input word is always either a string of lowercase 
# letters, or the empty string "".
#
# You will want to use the SCRABBLE_LETTER_VALUES dictionary defined at the top 
# of ps_0.py. You should not change its value.
#
# Do not assume that there are always 7 letters in a hand! The parameter n is 
# the number of letters required for a bonus score (the maximum number of 
# letters in the hand). Our goal is to keep the code modular.

# Import variable from helper code
from ps4_0 import SCRABBLE_LETTER_VALUES
                                                    
# SOLUTION
def getWordScore(word, n):
    """
    Returns the score for a word. Assumes the word is a valid word.

    The score for a word is the sum of the points for letters in the
    word, multiplied by the length of the word, PLUS 50 points if all n
    letters are used on the first turn.

    Letters are scored as in Scrabble; A is worth 1, B is worth 3, C is
    worth 3, D is worth 2, E is worth 1, and so on (see SCRABBLE_LETTER_VALUES)

    word: string (lowercase letters)
    n: integer (HAND_SIZE; i.e., hand size required for additional points)
    returns: int >= 0
    """
    score = 0

    # Score each letter as in Scrabble
    for letter in word:
        score += SCRABBLE_LETTER_VALUES[letter]
    
    # Apply score multiplier for word length
    score *= len(word)

    # Provide 50 point bonus for using all letters
    if len(word) == n:
        score += 50
    
    return score    
