2
2
3
3
4
4
def main ():
5
- """
6
- Main entry point of the Scrabble game.
7
- """
5
+ """Main entry point of the Scrabble game."""
8
6
print ('*' * 10 + "Welcome to the Scrabble game" + '*' * 10 )
9
7
print ("Let's start playing!!\n " )
10
8
score_board = {}
@@ -16,7 +14,7 @@ def main():
16
14
print ('*' * 40 )
17
15
print ("Thank you for your time. Have a Nice day!" )
18
16
19
-
17
+
20
18
def valid (word ):
21
19
"""
22
20
Checks if a word is valid by checking its meaning using PyDictionary.
@@ -26,9 +24,9 @@ def valid(word):
26
24
bool: True if the word is valid, False otherwise.
27
25
"""
28
26
dictionary = PyDictionary ()
29
- return dictionary .meaning (word ) is not None
27
+ return dictionary .meaning (word ) is not None
28
+
30
29
31
-
32
30
def compute_score (word ):
33
31
"""
34
32
Computes the score for a given word based on a score list.
@@ -40,22 +38,21 @@ def compute_score(word):
40
38
ValueError: If the word is invalid or contains non-alphabetic characters.
41
39
"""
42
40
score_list = {
43
- 'a' : 1 , 'b' : 3 , 'c' : 3 , 'd' : 2 , 'e' : 1 , 'f' : 4 , 'g' : 2 ,
44
- 'h' : 4 , 'i' : 1 , 'j' : 8 , 'k' : 5 , 'l' : 1 , 'm' : 3 , 'n' : 1 ,
45
- 'o' : 1 , 'p' : 3 , 'q' : 10 , 'r' : 1 , 's' : 1 , 't' : 1 , 'u' : 1 ,
41
+ 'a' : 1 , 'b' : 3 , 'c' : 3 , 'd' : 2 , 'e' : 1 , 'f' : 4 , 'g' : 2 ,
42
+ 'h' : 4 , 'i' : 1 , 'j' : 8 , 'k' : 5 , 'l' : 1 , 'm' : 3 , 'n' : 1 ,
43
+ 'o' : 1 , 'p' : 3 , 'q' : 10 , 'r' : 1 , 's' : 1 , 't' : 1 , 'u' : 1 ,
46
44
'v' : 4 , 'w' : 4 , 'x' : 8 , 'y' : 4 , 'z' : 10 }
47
45
score = 0
48
46
if word .isalpha ():
49
47
if valid (word ):
50
48
for char in word :
51
49
score += score_list [char .lower ()]
52
50
return score
53
- else :
54
- raise ValueError ("Invalid word" )
51
+ raise ValueError ("Invalid word" )
55
52
else :
56
53
raise ValueError ("Word should only contain alphabetic characters" )
57
54
58
-
55
+
59
56
def player_count ():
60
57
"""
61
58
Prompts the user to input the number of players for the game.
@@ -73,7 +70,7 @@ def player_count():
73
70
except ValueError as e :
74
71
print (str (e ))
75
72
76
-
73
+
77
74
def get_input (score_board ):
78
75
"""
79
76
Retrieves the word input from each player and updates their scores.
@@ -99,10 +96,11 @@ def get_input(score_board):
99
96
continue
100
97
return score_board
101
98
102
-
99
+
103
100
def winner (score_board ):
104
101
"""
105
102
Determines the winner(s) based on the highest scores.
103
+
106
104
Args:
107
105
score_board (dict): The dictionary storing the scores of each player.
108
106
Returns:
@@ -117,10 +115,8 @@ def winner(score_board):
117
115
if len (winners ) > 1 :
118
116
return f"It's a tie. The winners are { ', ' .join (winners )} !!"
119
117
return f"The winner is { winners [0 ]} !"
120
- else :
121
- return "No players found. Game over!"
118
+ return "No players found. Game over!"
122
119
123
120
124
121
if __name__ == "__main__" :
125
122
main ()
126
-
0 commit comments