Advertisement
Guest User

Untitled

a guest
Jul 13th, 2017
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. SCRABBLE_LETTER_VALUES = {
  2. 'a': 1, 'b': 3, 'c': 3, 'd': 2, 'e': 1, 'f': 4, 'g': 2, 'h': 4, 'i': 1, 'j': 8, 'k': 5, 'l': 1, 'm': 3, 'n': 1, 'o': 1, 'p': 3, 'q': 10, 'r': 1, 's': 1, 't': 1, 'u': 1, 'v': 4, 'w': 4, 'x': 8, 'y': 4, 'z': 10}
  3. li = []
  4. def getWordScore(word, n):
  5. """
  6. Returns the score for a word. Assumes the word is a valid word.
  7.  
  8. The score for a word is the sum of the points for letters in the
  9. word, multiplied by the length of the word, PLUS 50 points if all n
  10. letters are used on the first turn.
  11.  
  12. Letters are scored as in Scrabble; A is worth 1, B is worth 3, C is
  13. worth 3, D is worth 2, E is worth 1, and so on (see SCRABBLE_LETTER_VALUES)
  14.  
  15. word: string (lowercase letters)
  16. n: integer (HAND_SIZE; i.e., hand size required for additional points)
  17. returns: int >= 0
  18. """
  19. for letters in word:
  20. li.append(SCRABBLE_LETTER_VALUES[letters])
  21. if len(word) <= 0:
  22. return 0
  23. elif len(word) == n:
  24. summ = sum(li)
  25. result = summ*len(word) + 50
  26. else:
  27. summ = sum(li)
  28. result = summ*len(word)
  29. return result
  30.  
  31. li.clear()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement