Answered step by step
Verified Expert Solution
Question
00
1 Approved Answer
pls use python do this Problem 3. Valid words At this point, we have written code to generate a random hand and display that hand
pls use python do this Problem 3. Valid words At this point, we have written code to generate a random hand and display that hand to the user. We can also ask the user for a word (Pythons input) and score the word (using your get_word_score). However, at this point we have not written any code to verify that a word given by a player obeys the rules of the game. A valid word is in the word list and it is composed entirely of letters from the current hand. Implement the is_valid_word function. def is_valid_word(word, hand, word_list): """ Returns True if word is in the word_list and is entirely composed of letters in the hand. Otherwise, returns False. Does not mutate hand or word_list. word: string hand: dictionary (string -> int) word_list: list of lowercase strings """ # TO DO... Testing: Make sure the test_is_valid_word tests pass. In particular, you may want to test your implementation by calling it multiple times on the same hand what should the correct behavior be? Problem 4. Playing a hand We are now ready to begin writing the code that interacts with the player. Implement the play_hand function. This function allows the user to play out a single hand. def play_hand(hand, word_list): """ Allows the user to play the given hand, as follows: * The hand is displayed. * The user may input a word. * An invalid word is rejected, and a message is displayed asking the user to choose another word. * When a valid word is entered, it uses up letters from the hand. * After every valid word: the score for that word is displayed, the remaining letters in the hand are displayed, and the user is asked to input another word. * The sum of the word scores is displayed when the hand finishes. * The hand finishes when there are no more unused letters. The user can also finish playing the hand by inputing a single period (the string '.') instead of a word. hand: dictionary (string -> int) word_list: list of lowercase strings """ # TO DO ... Testing: Try out your implementation as if you were playing the game. Note: Do not assume that there will always be 7 letters in a hand! The global variable HAND_SIZE represents this value. Here is some example output of play_hand (your output may differ, depending on what messages you print out): Case #1 Current Hand: a c i h m m z Enter word, or a "." to indicate that you are finished: him "him" earned 24 points. Total: 24 points Current Hand: a c m z Enter word, or a "." to indicate that you are finished: cam "cam" earned 21 points. Total: 45 points Current Hand: z Enter word, or a "." to indicate that you are finished: . Total score: 45 points. Case #2 Current Hand: a s t t w f o Enter word, or a "." to indicate that you are finished: tow "tow" earned 18 points. Total: 18 points Current Hand: a s t f Enter word, or a "." to indicate that you are finished: tasf Invalid word, please try again. Current Hand: a s t f Enter word, or a "." to indicate that you are finished: fast "fast" earned 28 points. Total: 46 points. Total score: 46 points.
pls use python do this
Problem 3. Valid words
At this point, we have written code to generate a random hand and display that hand to the user. We can also ask the user for a word (Pythons input) and score the word (using your get_word_score). However, at this point we have not written any code to verify that a word given by a player obeys the rules of the game.
A valid word is in the word list and it is composed entirely of letters from the current hand.
Implement the is_valid_word function.
def is_valid_word(word, hand, word_list):
"""
Returns True if word is in the word_list and is entirely
composed of letters in the hand. Otherwise, returns False.
Does not mutate hand or word_list.
word: string
hand: dictionary (string -> int)
word_list: list of lowercase strings
"""
# TO DO...
Testing: Make sure the test_is_valid_word tests pass. In particular, you may want to test your implementation by calling it multiple times on the same hand what should the correct behavior be?
Problem 4. Playing a hand
We are now ready to begin writing the code that interacts with the player.
Implement the play_hand function. This function allows the user to play out a single hand.
def play_hand(hand, word_list):
"""
Allows the user to play the given hand, as follows:
* The hand is displayed.
* The user may input a word.
* An invalid word is rejected, and a message is displayed asking
the user to choose another word.
* When a valid word is entered, it uses up letters from the hand.
* After every valid word: the score for that word is displayed,
the remaining letters in the hand are displayed, and the user
is asked to input another word.
* The sum of the word scores is displayed when the hand finishes.
* The hand finishes when there are no more unused letters.
The user can also finish playing the hand by inputing a single
period (the string '.') instead of a word.
hand: dictionary (string -> int)
word_list: list of lowercase strings
"""
# TO DO ...
Testing: Try out your implementation as if you were playing the game.
Note: Do not assume that there will always be 7 letters in a hand! The global variable HAND_SIZE represents this value. Here is some example output of play_hand (your output may differ, depending on what messages you print out):
Case #1
Current Hand: a c i h m m z
Enter word, or a "." to indicate that you are finished: him
"him" earned 24 points. Total: 24 points
Current Hand: a c m z
Enter word, or a "." to indicate that you are finished: cam
"cam" earned 21 points. Total: 45 points
Current Hand: z
Enter word, or a "." to indicate that you are finished: .
Total score: 45 points.
Case #2
Current Hand: a s t t w f o
Enter word, or a "." to indicate that you are finished: tow
"tow" earned 18 points. Total: 18 points
Current Hand: a s t f
Enter word, or a "." to indicate that you are finished: tasf
Invalid word, please try again.
Current Hand: a s t f
Enter word, or a "." to indicate that you are finished: fast
"fast" earned 28 points. Total: 46 points.
Total score: 46 points.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started