-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproject.py
More file actions
93 lines (83 loc) · 1.67 KB
/
project.py
File metadata and controls
93 lines (83 loc) · 1.67 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
from random import sample
from collections import Counter
from sys import exit
def main():
random_letters()
user_input = str(input("What is your word: ").strip().lower())
check = check_word(user_input)
points = word_score(check)
print(f"{points} points, Well Done!")
def random_letters():
letters = Counter(
a=9,
b=2,
c=2,
d=4,
e=12,
f=2,
g=3,
h=2,
i=9,
j=1,
k=1,
l=4,
m=2,
n=6,
o=8,
p=2,
q=1,
r=6,
s=4,
t=6,
u=4,
v=2,
w=2,
x=1,
y=2,
z=1,
)
list_of_letters = list(sorted(letters.elements()))
hand = sample(list_of_letters, 7)
print(hand)
def check_word(user_input):
with open("Collins Scrabble Words (2019).txt") as file:
words = set(word.strip().lower() for word in file)
if user_input in words:
return user_input
else:
exit("Unfortunately that is not a word, better luck next time!")
def word_score(user_input):
score = {
"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,
}
word_total = 0
for letter in user_input:
word_total += score[letter]
return word_total
if __name__ == "__main__":
main()