Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

       

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

Step by Step Solution

3.46 Rating (156 Votes )

There are 3 Steps involved in it

Step: 1

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 ... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction to Java Programming, Comprehensive Version

Authors: Y. Daniel Liang

10th Edition

133761312, 978-0133761313

Students also viewed these Programming questions