Create a program that plays the game 'Hangman'. Randomly select a 5-letter word from the 'dictionary.py'...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Create a program that plays the game 'Hangman'. Randomly select a 5-letter word from the 'dictionary.py' file to use as the word the user needs to guess. At the beginning, display the empty gallows and 5 blank spaces that represents the word they are supposed to guess. Then, repeatedly prompt the user to guess a letter that's in the word. If they guess correctly, fill in the correct blank spaces with that letter. If they guess incorrectly, add a part of the hangman to the gallows and add the letter to the list of incorrect guesses. If they do not guess the word by the time the hangman is complete (6 incorrect turns), then they lose. As a hint to the user, also display the list of letters that they haven't used yet. Create the following functions for your program: 1. display_gallows (num_incorrect) - given the number of incorrect guesses the user has made, display the state of the hangman on the gallows (ex. zero incorrect guesses should show an empty gallows, 6 incorrect guesses should show the complete hanged man). 2. display_correct (correct) - given the list of correct guesses, display each of the letters in their correct locations separated by spaces. 3. display incorrect (incorrect) - given the list of incorrect guesses, sort the list and then display each letter separated by spaces. 4. In your main function, create a loop that repeats until the user chooses to quit. Choose a random word from the words list (this file is given on Canvas, include the list by putting from dictionary import words' at the top of your program), then create two lists, one for the incorrect guesses (which starts off empty), and the other for the correct guesses (starts with 5 blank spaces ('_')). Create two counters, one for the number of correct guesses made, and the other for the number of incorrect guesses. Create a loop that will repeat until the user guesses all 5 letters in the word, or until the user has made 6 incorrect guesses. Every round, display the incorrect guesses, the gallows, the correct guesses, the letters remaining, and then prompt the user to enter their guess. Check to make sure that all user input is valid (ie. it is a letter A-Z, and not a letter they've already guessed). If the guess was correct, add it to the list of correct guesses in the correct spot(s), if it was not, add it to the list of incorrect guesses and tally the correct or incorrect guess. Display whether they won or lost, if they lose, show the correct answer. display_letters_remaining (incorrect, correct) - given the list of incorrect guesses and the list of correct guesses, display the list of remaining letters in the alphabet to choose from. Example Output: -Hangman- Incorrect selections: ====== 11/ Letters remaining: ABCDEFGHIJ KLMNOPQRSTUVWXYZ Create a program that plays the game 'Hangman'. Randomly select a 5-letter word from the 'dictionary.py' file to use as the word the user needs to guess. At the beginning, display the empty gallows and 5 blank spaces that represents the word they are supposed to guess. Then, repeatedly prompt the user to guess a letter that's in the word. If they guess correctly, fill in the correct blank spaces with that letter. If they guess incorrectly, add a part of the hangman to the gallows and add the letter to the list of incorrect guesses. If they do not guess the word by the time the hangman is complete (6 incorrect turns), then they lose. As a hint to the user, also display the list of letters that they haven't used yet. Create the following functions for your program: 1. display_gallows (num_incorrect) - given the number of incorrect guesses the user has made, display the state of the hangman on the gallows (ex. zero incorrect guesses should show an empty gallows, 6 incorrect guesses should show the complete hanged man). 2. display_correct (correct) - given the list of correct guesses, display each of the letters in their correct locations separated by spaces. 3. display incorrect (incorrect) - given the list of incorrect guesses, sort the list and then display each letter separated by spaces. 4. In your main function, create a loop that repeats until the user chooses to quit. Choose a random word from the words list (this file is given on Canvas, include the list by putting from dictionary import words' at the top of your program), then create two lists, one for the incorrect guesses (which starts off empty), and the other for the correct guesses (starts with 5 blank spaces ('_')). Create two counters, one for the number of correct guesses made, and the other for the number of incorrect guesses. Create a loop that will repeat until the user guesses all 5 letters in the word, or until the user has made 6 incorrect guesses. Every round, display the incorrect guesses, the gallows, the correct guesses, the letters remaining, and then prompt the user to enter their guess. Check to make sure that all user input is valid (ie. it is a letter A-Z, and not a letter they've already guessed). If the guess was correct, add it to the list of correct guesses in the correct spot(s), if it was not, add it to the list of incorrect guesses and tally the correct or incorrect guess. Display whether they won or lost, if they lose, show the correct answer. display_letters_remaining (incorrect, correct) - given the list of incorrect guesses and the list of correct guesses, display the list of remaining letters in the alphabet to choose from. Example Output: -Hangman- Incorrect selections: ====== 11/ Letters remaining: ABCDEFGHIJ KLMNOPQRSTUVWXYZ
Expert Answer:
Answer rating: 100% (QA)
Here the python code for the above code provided below import random List of words for the game words apple banana cherry date elderberry fig grape honeydew kiwi lemon Function to display the hangman ... View the full answer
Related Book For
Introduction to Java Programming, Comprehensive Version
ISBN: 978-0133761313
10th Edition
Authors: Y. Daniel Liang
Posted Date:
Students also viewed these programming questions
-
Suppose announcers at a certain radio station say that they are at "92.8 on your FM dial," meaning that they transmit at a frequency of 92.8 MHz (92.8 megahertz, or 92.8 million cycles per second)....
-
In this assignment, you will create a program that allows theuser to draw in a window using brushes of different sizes andcolors. The user will be able to change the size and color of thebrush using...
-
All elements of the structure in Figure P3?47 have the same AE except element 1, which has an axial stiffness of 2AE. Find the displacements of the nodes and the stresses in elements 2, 3, and 4 by...
-
Question 2A) Explain the differences between right issues and bonusissues. Your answer should include the advantages and disadvantagesof both right issues and bonus issues. [ 8marks}b) Explain pos 0...
-
The Expanding Universe a cosmologist who is studying the light from a galaxy bas identified the spectrum of hydrogen but finds that the wavelengths are somewhat shifted from those found in the...
-
Read the definitions of NOPREFIX(A) and NOEXTEND(A) in Problem 1.40. a. Show that the class of CFLs is not closed under NOPREFIX. b. Show that the class of CFLs is not closed under NOEXTEND. Problem...
-
Although radiation is important in heat transfer, an analogous model can be used in the design of photochemical reactors. The modeling of these reactors requires that the radiation intensity be...
-
What will be the nominal rate of return on a preferred stock with a $100 par value, a stated dividend of 8 percent of par, and a current market price of? (a) $60, (b) $80, (c) $100, and (d) $140?
-
Units Beginning work in process inventory 32,000 Percent Complete 65% Percent Complete 35% Units started this period 410,000 Completed and transferred out 412,000 Ending work in process inventory...
-
It's amazing how much difference there is in the way proposals are presented at two different firms," said John Woods to his assistant, Pete Madsen, as he pointed to the stack of capital investment...
-
4. Explain the following: a) Magnet Schools b) Charter Schools c) Returns to Education d) Direct Student Loans
-
There are some typical input artifacts for object-oriented design. identify some of the input artifacts ?
-
In the following cases, determine whether the employment income is taxable in Canada or not. Case A (3 marks) - Ripinderjit, who was originally born in Windsor Ontario and is a Canadian citizen, now...
-
You attended a conference "Future of Taxation Advice" held by these associations and your employer asks for a summary. You are asked to interpret the graph below "Demand Curve for Taxation Advice"....
-
Consider a trip you might take overseas to Japan. Who is the supplier of dollars? Who demands dollars? What is the price of a Japanese currency (YEN)? Do you want the price to be high or low as the...
-
Consider a two station line. The first station pulls from an infinite supply of raw materials (i.e., there are always jobs available at the buffer of the first station). Between the two stations...
-
Let be the volume enclosed by a piecewise smooth closed surface S. Then ff Vox Vu-nds is equal to [ff (ou) dv fff (Vo Vy) dv V fff div (by) dv 0
-
The words without recourse on an indorsement means the indorser is: a. not liable for any problems associated with the instrument. b. not liable if the instrument is dishonored. c. liable personally...
-
Write a program that rotates a rectangle 15 degrees right when the Rotate button is clicked, as shown in Figure 15.24b. Rotate (b)
-
Listing 5.4, SubtractionQuizLoop.java, generates five random subtraction questions. Revise the program to generate ten random addition questions for two integers between 1 and 15. Display the correct...
-
Rewrite the Course class in Listing 10.6. Use an ArrayList to replace an array to store students. Draw the new UML diagram for the class. You should not change the original contract of the Course...
-
The Jenkins supermarket manager claims that the scanning errors on purchased items are random, and about half of the errors are in favor of the supermarket. Decide whether the statement makes sense...
-
At a particular moment, the U.S. Census Bureau population clock shows that the global population is 7,118,233,027 people. Describe the accuracy and precision of that population number. Data From...
-
When recording the weight of a watermelon, a supermarket clerk writes the wrong number. Is this type of error a random error or a systematic error? Explain.
Study smarter with the SolutionInn App