-
Notifications
You must be signed in to change notification settings - Fork 57
/
word scores.py
23 lines (20 loc) · 830 Bytes
/
word scores.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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
"""
# TO DO ... <-- Remove this comment when you code this function
score = 0
for i in word:
score += SCRABBLE_LETTER_VALUES[i]
if len(word) == n:
return (score * len(word)) + 50
else:
return score * len(word)