(Python) In this assignment you will write a program for a popular game Hangman. Your program will generate a legitimate

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

(Python) In this assignment you will write a program for a popular game Hangman. Your program will generate a legitimate

Post by answerhappygod »

(Python)
In this assignment you will write a program for a popular gameHangman. Your program will generate a legitimate dictionary wordand ask the user to guess the word one letter at a time. The userwill have restricted number of lives (attempts of guessing theword) that will be set up in the beginning of the game. After theuser uses all lives or guesses the word correctly, the programswill ask the user if she wants to play again. Here are the snippetsof the program output. Be aware that your program output shouldmatch this format exactly. Please read the instructions carefullyand completely before starting to work on your program!
In the beginning a program should output the followingmessages:
If the user chooses 7 then the program prints:
If the user chooses 3 then the program prints:
If the user does not enter the valid input (for example, theuser hits just “Enter” key or chooses numbers outside of thespecified range of 3 – 12) the program should set up defaultparameters and inform the user about them:
After that the program prints the program interface includingthe list of letters already chosen by the user, the word with thehidden letters shown as double underscores, the number of livesleft shown as an uppercase letter O, and a prompt to choose a newletter:
Let’s assume that the dictionary word APPLE has been selected bythe program. If the user enters the first letter E, then theprogram outputs these lines:
If the user enters the second letter S, then the program outputsthe following lines:
If the user enters the third letter P, then the program outputsthis:
If the user enters again letter E, the program print themessage:
If the user lost all lives, the program prints the followingmessages:
If the user won, the program prints these messages:
If the user types ‘Y’ or ‘y’ the program starts a new game andprint the following message again:
Otherwise it prints the following new message andterminates:
If a word has a hyphen, then the hyphen should be shown in thebeginning of the program. For example, if the hidden word isT-shirt, then the hidden word should be displayed as shownbelow:
Programming Approaches
Your source file should benamed hangman.py and should start withthe header (a comment block) where you write important informationabout the source file including who created it, when it is created,what the purpose of it, and how to use it. You are also required toimplement two functions: import_dictionary(filename) and get_game_options().
The function import_dictionary(filename) should create adictionary from a text file (a dictionary file) that is provided toyou (See below). The dictionary file contains legitimate 2,542words from an English vocabulary, each word is written on aseparate line. Your program should read the file line by line andadd words to the dictionary. The function should return thedictionary.
The function get_game_options() should ask the user to selectgame options such as a dictionary word size and a number of lives.The function should return a tuple of selected game options (a wordsize and a number of lives).
The general control flow structure of your program should bebased on a nested while loop where the outer loop is used to play agame several times and the inner loop is used to run one game (Readthe code below). You need to use an elif statement (for theanalysis of menu options), a for loop (for reading a file), and atleast one string method such as strip(), join(), isalpha(),upper(), or lower(). You also need to use a list and a dictionaryin your program to get the full credit. A dictionary is used forstoring a vocabulary sorted by word size, and at least three listsare used for storing letters of the hidden word, guessed letters,and words of the same size (as dictionary values).
If you prefer, you can use the following template filehangman.py. You can download it from Files/ProgrammingAssignments/PA1.
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply