-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscrabble.py
More file actions
62 lines (33 loc) · 1.17 KB
/
scrabble.py
File metadata and controls
62 lines (33 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
letters = ["A", "B", "C", "D", "E", "F", "G", "H",
"I", "J", "K", "L", "M", "N", "O", "P", "Q", "R",
"S", "T", "U", "V", "W", "X", "Y", "Z", " "]
points = [1, 3, 3, 2, 1, 4, 2, 4, 1, 8, 5, 1, 3, 4, 1, 3, 10, 1, 1, 1, 1, 4, 4, 8, 4, 10, 0]
# Create a point dict
letter_points = {}
for x in range(27):
letter_points[letters[x]] = points[x]
# Determine score of a word
def score_word(word):
point_total = 0
for ch in word.upper():
if ch in letter_points:
point_total += letter_points[ch]
return point_total
print(score_word("cat"))
# Create a dict of a player's word history
p_words = {
"player1" : ["BLUE", "TENNIS", "EXIT"],
"wordNerd" : ["EARTH", "EYES", "MACHINE"],
"Lexi Con" : ["ERASER", "BELLY", "HUSKY"],
"Prof Reader" : ["ZAP", "COMA", "PERIOD"]
}
# Q10 - Empty Dict to store player's points
player_to_points = {}
#
for player, words in p_words.items():
p_points = 0
for word in words:
p_points += score_word(word)
player_to_points[player] = p_points
print(player_to_points)
# print(score_word("MACHINE"))