Your task is to implement a variation of the classic word game Hangman, which involves players
guessing the letters in a word chosen at random with a finite number of guesses. While there are
alternate versions such as category Hangman and Wheel of Fortune, which involve players
guessing idioms, places, names and so on, we will be sticking with the traditional version.
Requirements:
You will implement a function called main that allows users to play an interactive hangman game
against the computer. The computer should pick a word, and players should then try to guess letters
in the word until they win or run out of guesses.
Here is the overarching behaviour we expect:
1. The program should load a list of available words from the text file provided. Note that
the file you have been given contains words in lowercase.
2. The computer should then select a word at random from the list at random.
3. The user is given a certain number of guesses at the beginning.
4. The game is interactive; the user inputs their guess and the computer either:
a. reveals the letter if it exists in the secret word
b. penalizes the user and updates the number of guesses remaining
5. The game ends when the user guesses the word, or runs out of available guesses.
You are going to make use of a common approach to computational problem solving, which
involves breaking the problem down into several logical subtasks to make things more
manageable. The file hangman.py contains several existing helper variables and functions
which you should use to help you complete the task.
For this challenge, you will extend the existing program so that players scores are saved to and
read from a text file e.g. scores.txt. You should ask for the player’s name at the start of each new
game and use it to load their previous high score. If they manage to beat their personal best while
playing, ask them if they would like to update the leaderboard and do so if prompted.
To do this, you should create two new functions:
• A function to retrieve the existing high score for the current player called: get_score.
This should take a single argument, the players name and return their high score. If they
don’t have a high score return 0 or None. Players without a previous high score should
always be asked whether they would like to store their score.
• A function to save a new high score for the current player called: save_score. This
should take two arguments (the players name and score). The function does not need to
have a return value, but should handle writing the latest score to the text file. If a player
already has a lower score saved in the file, update it instead.
Your game will also need a more robust menu, it should contain options to play the game, load the
leaderboard or quit. Players should return here after playing or viewing the leaderboard. Selecting
the option to quit should close the program after printing a goodbye message. The logic for this
should be contained in your main function, update it as required.
format :
import string
WORDLIST_FILENAME = "words.txt"
# Responses to in-game events
# Use the format function to fill in the spaces
responses = [
"I am thinking of a word that is {0} letters long",
"Congratulations, you won!",
"Your total score for this game is: {0}",
"Sorry, you ran out of guesses. The word was: {0}",
"You have {0} guesses left.",
"Available letters: {0}",
"Good guess: {0}",
"Oops! That letter is not in my word: {0}",
"Oops! You've already guessed that letter: {0}",
]
def choose_random_word(all_words):
return random.choice(all_words)
# end of helper code
# -----------------------------------
def load_words():
# TODO: Fill in your code here
pass
# Load the list of words into the variable wordlist
# Accessible from anywhere in the program
# TODO: uncomment the below line once
# you have implemented the load_words() function
# wordlist = load_words()
def is_word_guessed(word, letters_guessed):
# TODO: Fill in your the code here
pass
def get_guessed_word(word, letters_guessed):
# TODO: Fill in your code here
pass
# TODO: Fill in your code here
pass
def hangman(word):
print("Welcome to Hangman Ultimate Edition")
print("I am thinking of a word that is {0} letters long".format(len(word)))
print("-------------")
# TODO: Fill in your code here
# ---------- Challenge Functions (Optional) ----------
def get_score(name):
pass
def save_score(name, score):
pass
# When you've completed your hangman function, scroll down to the bottom
# of the file and uncomment the last lines to test
# (hint: you might want to pick your own
# word while you're doing your own testing)
# -----------------------------------
def main():
# Uncomment the line below once you have finished testing.
# word = choose_random_word(wordlist)
# Uncomment the line below once you have implemented the hangman function.
# hangman(word)
pass
# Driver function for the program
if __name__ == "__main__":
main()
Trending nowThis is a popular solution!
Step by stepSolved in 3 steps with 1 images
- Recall the geometry example from class. Create new modules for triangles, spheres, and cylinders and populate them with functions for calculating perimeter and area in the 2-D case (triangles) and volume and surface area in the 3-D cases (spheres and cylinders). Now modify the geometry.py file to work with these as options for the user. SUBMIT: - A modified geometry.py file that works with the new modules you have created. - triangle.py, sphere.py, and cylinder.py files which contain the methods specified above. Attached: original geometry.py and an example for sphere.pyarrow_forwardI am looking for the following in your program: Python GUI-based MP3 Player Project #3: Python GUI-based MP3 Player 1. Ability to select a folder / directory for MP3s. (HINT: There’s a function/method in filedialog of tkinter to do this. In other words, you'll need the following import: from tkinter import messagebox, filedialog 2. Ability to play selected MP3s. 3. Ability to pause the current MP3. 4. Quit button/function to exit application. 5. Use a list to store and display the mp3 file names. You will need to demonstrate your mastery of lists, loops, and GUI elements within this program. Submission will include: 1. Python program named myplayer.py 2. Data Flow Diagrams / Pseudocode 3. If choosing an alternate library to tkinter or pygame, provide instructions and download links for the alternate library.arrow_forwardYou are working for a major car manufacturer and have been tasked with creating an application to maintain vehicle inventory records for one of its dealerships. Create a class to maintain a Dealership. A dealership has the following information that must be stored in the Dealership class: the dealership name, the maximum number of vehicles that the dealership’s lot can hold, and a vector of the vehicles currently on the lot. The information for each vehicle should be encapsulated in a Vehicle class and should include the vehicle’s make, model, and year. Your Dealership class should support operations (functions) to add a vehicle to the dealership’s inventory (vector) and to list all vehicle records (i.e. print out the make, model, and year of each vehicle object in the vector). Your Vehicle class should include operations to allow entry of the make, model, and year, and to return the values in these variables (In other words, you need a separate setter and getter for each data…arrow_forward
- Create a new project named lab10. You will be implementing two classes: A SolarSystem class, and a Planet class. The SolarSystem contains Planet objects stored in a vector. A UML diagram for the Solar System and Planet classes The first part you should implement is the Planet class. Don't add the SolarSystem files to the project at the beginning, just work on the Planet class. Test the different overloaded operators as we did during lecture for your Planet class, and then move on to the SolarSystem class. The SolarSystem default constructor should resize the vector to zero. The default constructor values for Planet can be whatever you’d like, but make the mass a very small number, so later on when you're looking for the largest planet, it doesn't use the default Planet value. The addPlanets() method will take a number as an argument for the number of Planets that will be in your SolarSystem. So if you call addPlanets with 5 as an argument, there will be 5 Planets to add to the…arrow_forwardRefer to the following interface: Provide two examples (screenshots) that in many ways could improve the above or similar interface using the principles of direct manipulation. Explain the relevant improvements as well. (Examples might have different object, labels and organization)arrow_forwardI need help with the main function, please. I have all classes I need I just need the main functionarrow_forward
- You have been asked to write a Java program that will determine the attendance performance of students undertaking OOP module during the Fall 20 semester. There are fifteen weeks conducted during the semester for four hours each week. The instructor can mark attendance for each hour of the class. Comment should be included in the program which explains each line of code. The requirements of your Java program is listed below a) Use an interface to specify all the functions that should be in place in the program. That should include the followingo Calculating the overall attendance Percentage.o Determining the performance result (55% or higher attendance is accepted for gradesotherwise the student is marked absent for the module).o Displaying all the relevant information on screen.arrow_forwardIn Checkpoint A, the game will not yet be playable as a two-player game. It will be playable by you in a type of "solitaire mode." Implement these functions from the template following the description (specification) in their docstring: show_top_card() get_top_card() add_card_to_discard() check_racko() find_and_replace() play_hand() The main function to drive the game has been provided. Missing input/output statements are part of play_hand() and left for you to implement, guided by the sample input/output. None of the other functions left to implement use input or print. The case / capitalization of user input should be ignored. On any invalid user input, the program should exit with a non-zero exit code. Hint: Use Python Tutor. as much as possible when testing gameplay. Zybooks requires you specify all your inputs in advance and it is less enjoyable to play that way. Sample input/output 1 When the inputs are: no yes 1 yes 5 yes 7 The expected behavior is (inputs are shown in-line)…arrow_forwardHelp, I am making a elevator simulation using polymorphism. I am not sure to do now. Any help would be appreciated. My code is at the bottom, that's all I could think off. There are 4 types of passengers in the system:Standard: This is the most common type of passenger and has a request percentage of 70%. Standard passengers have no special requirements.VIP: This type of passenger has a request percentage of 10%. VIP passengers are given priority and are more likely to be picked up by express elevators.Freight: This type of passenger has a request percentage of 15%. Freight passengers have large items that need to be transported and are more likely to be picked up by freight elevators.Glass: This type of passenger has a request percentage of 5%. Glass passengers have fragile items that need to be transported and are more likely to be picked up by glass elevators. public abstract class Passenger { public static int passangerCounter = 0; private String passengerID; protected…arrow_forward
- What happens if the programmer removes the member function getBalance (), and instead substitutes it with sac. getBalance() in conjunction with sac.balance inside the displayBalance instruction? Why? You will need to make the appropriate adjustments to the application so that it can continue to run once these changes have been made.arrow_forwardAs the first step in writing an application for the local book store, we will design and implement a Book class that will define the data structure of the application. Each book has a name, author, type (paperback, hardback, magazine), integer ID and pageCount. Provide some data validation in the appropriate method to ensure that the ID and pageCount are not negative. Design and implement a Book class with separation, i.e., separate all functions and methods into both the prototype and an implementation below the main. Provide constructor methods for Book(void), Book(name, author), and one for all components Book(name, author, type, ID, pageCount) Provide accessor (get and set) methods for each property as well as a display method. Provide data validation for the ID and pageCount in the appropriate methods. Provide a method to calculate the cost for buying books (with a 7.75% sales tax) according to the following chart: Hardcover: $29.95 per book Paperback:…arrow_forwardIn this lab, you create a derived class from a base class, and then use the derived class in a C++ program. The program should create two Motorcycle objects, and then set the Motorcycle’s speed, accelerate the Motorcycle object, and check its sidecar status. Instructions Ensure the file named Motorcycle.cpp is open in your editor. Create the Motorcycle class by deriving it from the Vehicle class. Use a public derivation. In the Motorcycle class, create a private attribute named sidecar. The sidecar attribute should be data type bool. Write a public set method to set the value for sidecar. Write a public get method to retrieve the value of sidecar. Write a public accelerate() method. This method overrides the accelerate() method inherited from the Vehicle class. Change the message in the accelerate() method so the following is displayed when the Motorcycle tries to accelerate beyond its maximum speed: "This motorcycle cannot go that fast". Open the file named…arrow_forward
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY