Skip to content

Commit ec4ac3b

Browse files
committed
Update scrabble.py as per guidelines
1 parent 44601e9 commit ec4ac3b

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

Scrabble/scrabble.py

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33

44
def main():
5-
"""
6-
Main entry point of the Scrabble game.
7-
"""
5+
"""Main entry point of the Scrabble game."""
86
print('*' * 10 + "Welcome to the Scrabble game" + '*' * 10)
97
print("Let's start playing!!\n")
108
score_board = {}
@@ -16,7 +14,7 @@ def main():
1614
print('*' * 40)
1715
print("Thank you for your time. Have a Nice day!")
1816

19-
17+
2018
def valid(word):
2119
"""
2220
Checks if a word is valid by checking its meaning using PyDictionary.
@@ -26,9 +24,9 @@ def valid(word):
2624
bool: True if the word is valid, False otherwise.
2725
"""
2826
dictionary = PyDictionary()
29-
return dictionary.meaning(word) is not None
27+
return dictionary.meaning(word) is not None
28+
3029

31-
3230
def compute_score(word):
3331
"""
3432
Computes the score for a given word based on a score list.
@@ -40,22 +38,21 @@ def compute_score(word):
4038
ValueError: If the word is invalid or contains non-alphabetic characters.
4139
"""
4240
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,
4644
'v': 4, 'w': 4, 'x': 8, 'y': 4, 'z': 10}
4745
score = 0
4846
if word.isalpha():
4947
if valid(word):
5048
for char in word:
5149
score += score_list[char.lower()]
5250
return score
53-
else:
54-
raise ValueError("Invalid word")
51+
raise ValueError("Invalid word")
5552
else:
5653
raise ValueError("Word should only contain alphabetic characters")
5754

58-
55+
5956
def player_count():
6057
"""
6158
Prompts the user to input the number of players for the game.
@@ -73,7 +70,7 @@ def player_count():
7370
except ValueError as e:
7471
print(str(e))
7572

76-
73+
7774
def get_input(score_board):
7875
"""
7976
Retrieves the word input from each player and updates their scores.
@@ -99,10 +96,11 @@ def get_input(score_board):
9996
continue
10097
return score_board
10198

102-
99+
103100
def winner(score_board):
104101
"""
105102
Determines the winner(s) based on the highest scores.
103+
106104
Args:
107105
score_board (dict): The dictionary storing the scores of each player.
108106
Returns:
@@ -117,10 +115,8 @@ def winner(score_board):
117115
if len(winners) > 1:
118116
return f"It's a tie. The winners are {', '.join(winners)}!!"
119117
return f"The winner is {winners[0]}!"
120-
else:
121-
return "No players found. Game over!"
118+
return "No players found. Game over!"
122119

123120

124121
if __name__ == "__main__":
125122
main()
126-

0 commit comments

Comments
 (0)