If you have tried playing Hangman against the computer, you may have noticed that it isn't...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
If you have tried playing Hangman against the computer, you may have noticed that it isn't always easy to beat the computer, especially when it selects an esoteric word (like "esoteric"!). It might be nice if you could ask the computer for a hint, such as a list of all the words that match what you have currently guessed. For example, if the hidden word is "tact", and you have so far guessed the letter "t", so that you know the solution is "t t", where you need to guess the two missing letters, it might be nice to know that the set of matching words (at least based on what the computer initially loaded) are: tact tart taut teat tent test text that tilt tint toot tort tout trot tuft twit We are going to have you create a variation of Hangman (we call this hangman with hints , and have provided an initial scaffold for writing it), with the property that if you guess the special character * the computer will find all the words from its loaded list that might match your current guessed word, and print out each of them. Of course, we don't recommend trying this at the first step, since this will print out all 55,900 words that we loaded! But if you are getting close to an answer and are running out of guesses, this might help. To do this, we are going to ask you to first complete two helper functions: 3A) Matching the current guessed word match with gaps takes two parameters: my word and other word. my word is an instance of a guessed word, in other words, it may have some _ 's in places (such as 't_t'). other ward is a normal English word. This function should return True if the guessed letters of my word match the corresponding letters of other word . It should return False if the two words are not of the same length or if a guessed letter in my word does not match the corresponding character in other word. Remember that when a letter is guessed, your code reveals all the positions at which that letter occurs in the secret word. Therefore, the hidden letter ( ) cannot be one of the letters in the word that has already been revealed. >> match_with_gaps ("te t", "tact") False >>> match_with_gaps ("a_ le", "banana") False >>> match_with_gaps ("a le", "apple") True >>> match_with_gaps ("a ple", "apple") False Hint: You may want to use strip() to get rid of the spaces in the word to compare lengths. 3B) Showing all possible matches show possible matches takes a single parameter: my word which is an instance of a guessed word, in other words, it may have some _ 's in places (such as 't__t'). This function should print out all words in wordlist (notice where we have defined this at the beginning of the file, line 51) that match my word . It should print "No matches found" if there are no matches. Example Usage: >>> show_possible_matches ("t_ t") tact tart taut teat tent test text that tilt tint toot tort tout trot tuft twit >>> show_possible_matches ("abbbb_ ") No matches found >>> show_possible_matches ("a pl_ ") ample amply 3C) Hangman with hints Now you should be able to replicate the code you wrote for hangman as the body of hangman_with_hints, then make a small addition to allow for the case where the user can guess an asterisk (*), in which case the computer will print out all the words that match that guess. The user should not lose a guess if the guess is an asterisk. Comment out the lines of code you used to play the original Hangman game: secret_word = choose_word (wordlist) hangman (secret_word) And uncomment out these lines of code we've provided at the bottom of the file to play your new game Hangman with Hints: #secret word = choose word (wordlist) #hangman_with_hints (secret_word) Sample Output: The output from guessing an asterisk should look like the sample output below. All other output should follow the Hangman game described in Part 2 above. Loading word list from file... 55900 words loaded. Welcome to the game Hangman! I am thinking of a word that is 5 letters long. You have 6 guesses left. Available letters: abcdefghijklmnopqrstuvwxyz Please guess a letter: a Good guess: a_ - - - You have 6 guesses left. Available letters: bcdefghijklmnopqrstuvwxyz Please guess a letter: 1 Good guess: a_ 1_ You have 6 guesses left. Available letters: bcdefghijkmnopqrstuvwxyz Please guess a letter: * Possible word matches are: addle adult agile aisle amble ample amply amyls angle ankle apple apply aptly arils atilt You have 6 guesses left. Loading word list from file... 55900 words loaded. Welcome to the game Hangman! I am thinking of a word that is 5 letters long. You have 6 guesses left. Available letters: abcdefghijklmnopqrstuvwxyz Please guess a letter: a Good guess: a_ You have 6 guesses left. Available letters: bcdefghijklmnopgrstuvwxyz Please guess a letter: 1 Good guess: a__ 1_ You have 6 guesses left. Available letters: bcdefghijkmnopqrstuvwxyz Please guess a letter: Possible word matches are: addle adult agile aisle amble ample amply amyls angle ankle apple apply aptly arils atilt You have 6 guesses left. Available letters: bcdefghijkmnopqrstuvwxyz Please guess a letter: e Good guess: a_ le If you have tried playing Hangman against the computer, you may have noticed that it isn't always easy to beat the computer, especially when it selects an esoteric word (like "esoteric"!). It might be nice if you could ask the computer for a hint, such as a list of all the words that match what you have currently guessed. For example, if the hidden word is "tact", and you have so far guessed the letter "t", so that you know the solution is "t t", where you need to guess the two missing letters, it might be nice to know that the set of matching words (at least based on what the computer initially loaded) are: tact tart taut teat tent test text that tilt tint toot tort tout trot tuft twit We are going to have you create a variation of Hangman (we call this hangman with hints , and have provided an initial scaffold for writing it), with the property that if you guess the special character * the computer will find all the words from its loaded list that might match your current guessed word, and print out each of them. Of course, we don't recommend trying this at the first step, since this will print out all 55,900 words that we loaded! But if you are getting close to an answer and are running out of guesses, this might help. To do this, we are going to ask you to first complete two helper functions: 3A) Matching the current guessed word match with gaps takes two parameters: my word and other word. my word is an instance of a guessed word, in other words, it may have some _ 's in places (such as 't_t'). other ward is a normal English word. This function should return True if the guessed letters of my word match the corresponding letters of other word . It should return False if the two words are not of the same length or if a guessed letter in my word does not match the corresponding character in other word. Remember that when a letter is guessed, your code reveals all the positions at which that letter occurs in the secret word. Therefore, the hidden letter ( ) cannot be one of the letters in the word that has already been revealed. >> match_with_gaps ("te t", "tact") False >>> match_with_gaps ("a_ le", "banana") False >>> match_with_gaps ("a le", "apple") True >>> match_with_gaps ("a ple", "apple") False Hint: You may want to use strip() to get rid of the spaces in the word to compare lengths. 3B) Showing all possible matches show possible matches takes a single parameter: my word which is an instance of a guessed word, in other words, it may have some _ 's in places (such as 't__t'). This function should print out all words in wordlist (notice where we have defined this at the beginning of the file, line 51) that match my word . It should print "No matches found" if there are no matches. Example Usage: >>> show_possible_matches ("t_ t") tact tart taut teat tent test text that tilt tint toot tort tout trot tuft twit >>> show_possible_matches ("abbbb_ ") No matches found >>> show_possible_matches ("a pl_ ") ample amply 3C) Hangman with hints Now you should be able to replicate the code you wrote for hangman as the body of hangman_with_hints, then make a small addition to allow for the case where the user can guess an asterisk (*), in which case the computer will print out all the words that match that guess. The user should not lose a guess if the guess is an asterisk. Comment out the lines of code you used to play the original Hangman game: secret_word = choose_word (wordlist) hangman (secret_word) And uncomment out these lines of code we've provided at the bottom of the file to play your new game Hangman with Hints: #secret word = choose word (wordlist) #hangman_with_hints (secret_word) Sample Output: The output from guessing an asterisk should look like the sample output below. All other output should follow the Hangman game described in Part 2 above. Loading word list from file... 55900 words loaded. Welcome to the game Hangman! I am thinking of a word that is 5 letters long. You have 6 guesses left. Available letters: abcdefghijklmnopqrstuvwxyz Please guess a letter: a Good guess: a_ - - - You have 6 guesses left. Available letters: bcdefghijklmnopqrstuvwxyz Please guess a letter: 1 Good guess: a_ 1_ You have 6 guesses left. Available letters: bcdefghijkmnopqrstuvwxyz Please guess a letter: * Possible word matches are: addle adult agile aisle amble ample amply amyls angle ankle apple apply aptly arils atilt You have 6 guesses left. Loading word list from file... 55900 words loaded. Welcome to the game Hangman! I am thinking of a word that is 5 letters long. You have 6 guesses left. Available letters: abcdefghijklmnopqrstuvwxyz Please guess a letter: a Good guess: a_ You have 6 guesses left. Available letters: bcdefghijklmnopgrstuvwxyz Please guess a letter: 1 Good guess: a__ 1_ You have 6 guesses left. Available letters: bcdefghijkmnopqrstuvwxyz Please guess a letter: Possible word matches are: addle adult agile aisle amble ample amply amyls angle ankle apple apply aptly arils atilt You have 6 guesses left. Available letters: bcdefghijkmnopqrstuvwxyz Please guess a letter: e Good guess: a_ le
Expert Answer:
Answer rating: 100% (QA)
import string import random wordsguessed def loadwords printLoading word ... View the full answer
Related Book For
Principles of managerial finance
ISBN: 978-0132479547
12th edition
Authors: Lawrence J Gitman, Chad J Zutter
Posted Date:
Students also viewed these accounting questions
-
You have just been told, Because we are going to finance this project with debt, its required rate of return must exceed the cost of debt. Do you agree or disagree? Explain.
-
Find all curves with the property that if the normal line is drawn at any point P on the curve, then the part of the normal line between and P the x-axis is bisected by the y-axis.
-
Find all curves with the property that if a line is drawn from the origin to any point (x, y) on the curve, and then a tangent is drawn to the curve at that point and extended to meet the -axis, the...
-
A water sprinkler sprays water over a distance of 30 feet while rotating through an angle of 135. What area of lawn receives water? 135 30 ft
-
Which of the following are pure substances and which are mixtures? For each, list all of the different phases present.
-
Which principle states that a person should only receive orders from one boss in an organization? (a) scalar (b) contingency (c) Hawthorne (d) unity of command
-
An HR consultant gives an applicant a 75% chance of getting a job after registering with his agency. If the applicant gets a job, then there is a 60% possibility that he would be satisfied and would...
-
The following statement was made by the vice president of finance of Orville Inc.: The managers of a company should use the same information as the shareholders of the firm. When managers use the...
-
The issue at hand is whether Burger Queen violated their duty of good faith towards Scheck by opening a new store close to his existing franchise, knowing it would harm his business. Scheck can...
-
Dwight Donovan, the president of Donovan Enterprises, is considering two investment opportunities. Because of limited resources, he will be able to invest in only one of them. Project A is to...
-
The subject is a small, multitenant office building with six tenants and one vacant suite. Leases in this market are typically written for five years at a flat rate, with the tenant paying the...
-
What is meant by tax incidence?
-
Once a market has reached its equilibrium price, it will never move away from it. Do you agree or disagree? Briefly explain.
-
Define consumer surplus. Draw a graph to show the area that represents consumer surplus.
-
Why is equilibrium in a competitive market considered to be efficient?
-
Define a Pigovian tax. Briefly list and explain the problems related to the implementation of the tax.
-
5. You are asked to evaluate the performance of two classification models, M1 and M2. The test set contains 26 attributes labelled A through Z. Given the following table Instance 1 True class...
-
5. How much would you need to deposit in an account now in order to have $5,000 in the account in 5 years? Assume the account earns 2% interest compounded monthly. 10. You deposit $300 each month...
-
When is the coefficient of variation preferred over the standard deviation for comparing asset risk?
-
What is an option? Define calls and puts. What role, if any, do call and put options play in the fund-raising activities of the financial manager?
-
Free cash how is often considered a more reliable measure of a companys income than reported earnings. What are same possible ways that corporate accountants might be able to change their earnings to...
-
A4-stroke, 4-cylinder, single acting spark ignition petrol engine develops \(20 \mathrm{~kW}\) brake power at \(3000 \mathrm{rpm}\). The following data are given : Bore \(=65 \mathrm{~mm}\), Stroke...
-
A six cylinder four stroke I.C. Engine is to develop \(100 \mathrm{~kW}\) i.p. at 800 RPM. The stroke to bare ratio is 1.25. Assuming Mechanical efficiency of \(80 \%\) and break mean effective...
-
The following data is available for a four stroke petrol engine stroke volume \(=6\) Litres. Mean effective pressure \(=6\) bar. Speed of engine \(=750\) RPM. Calculate i.p. of the engine.
Study smarter with the SolutionInn App