Python task: Task Overview 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. If you are unfamiliar with the rules of the game, please read the following before starting: http://en.wikipedia.org/wiki/Hangman_(game). You can also play an online version here. Don’t be intimidated - You’ll be given some skeleton code to get you started, it's easier than it looks! 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. Example format : # Hangman Game # ----------------------------------- # Helper code # You don't need to understand this helper code, # but you will have to know how to use the functions # (so be sure to read the docstrings!) import random 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 def get_remaining_letters(letters_guessed): # 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()
Python task: Task Overview 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. If you are unfamiliar with the rules of the game, please read the following before starting: http://en.wikipedia.org/wiki/Hangman_(game). You can also play an online version here. Don’t be intimidated - You’ll be given some skeleton code to get you started, it's easier than it looks! 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. Example format : # Hangman Game # ----------------------------------- # Helper code # You don't need to understand this helper code, # but you will have to know how to use the functions # (so be sure to read the docstrings!) import random 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 def get_remaining_letters(letters_guessed): # 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()
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
Related questions
Question
Python task:
Task Overview
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.
If you are unfamiliar with the rules of the game, please read the following before starting:
http://en.wikipedia.org/wiki/Hangman_(game). You can also play an online version here. Don’t
be intimidated - You’ll be given some skeleton code to get you started, it's easier than it looks!
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.
If you are unfamiliar with the rules of the game, please read the following before starting:
http://en.wikipedia.org/wiki/Hangman_(game). You can also play an online version here. Don’t
be intimidated - You’ll be given some skeleton code to get you started, it's easier than it looks!
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. Theprogram 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.
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
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.
Example format :
# Hangman Game
# -----------------------------------
# Helper code
# You don't need to understand this helper code,
# but you will have to know how to use the functions
# (so be sure to read the docstrings!)
import random
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
# -----------------------------------
# Helper code
# You don't need to understand this helper code,
# but you will have to know how to use the functions
# (so be sure to read the docstrings!)
import random
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
def get_remaining_letters(letters_guessed):
# 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()
# 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()
![Example Implementation (input in red):
Loading word list from file...
55900 words loaded.
Welcome to Hangman Ultimate Edition
Do you want to Play (p) view the leaderboard (1) or quit (g): P
Score
Name
Matthew Howell
Herbert Daly
7
5
3
Hiran Patel
Would you like to play (p) or view the leaderboard (1): p
What is your name: Matthew Howell
I am thinking of a word that is 2 letters long
You have 6 guesses left.
Available letters: abcdefghijklmnopqrstuvwxyz
Please gues a letter: 2
Good guess: =
You have 6 guesses left.
Available letters: bcdefghijklmnopgrstuvxyz
Please gues a letter: n
Good guess: an
Congratulations, you won!
Your total score for this game is: 9
A new personal best! Would you like to save your score (y/n): y
Ok, your score has been saved.
Do you want to Play (p) view the leaderboard (1) or quit (q) : 4
Thanks for playing, goodbye!](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fba87a338-86ce-43b8-9eb9-6a97197ccbb8%2F182c91b3-432d-4108-abbd-84674f688ccb%2Fuhudc6m_processed.png&w=3840&q=75)
Transcribed Image Text:Example Implementation (input in red):
Loading word list from file...
55900 words loaded.
Welcome to Hangman Ultimate Edition
Do you want to Play (p) view the leaderboard (1) or quit (g): P
Score
Name
Matthew Howell
Herbert Daly
7
5
3
Hiran Patel
Would you like to play (p) or view the leaderboard (1): p
What is your name: Matthew Howell
I am thinking of a word that is 2 letters long
You have 6 guesses left.
Available letters: abcdefghijklmnopqrstuvwxyz
Please gues a letter: 2
Good guess: =
You have 6 guesses left.
Available letters: bcdefghijklmnopgrstuvxyz
Please gues a letter: n
Good guess: an
Congratulations, you won!
Your total score for this game is: 9
A new personal best! Would you like to save your score (y/n): y
Ok, your score has been saved.
Do you want to Play (p) view the leaderboard (1) or quit (q) : 4
Thanks for playing, goodbye!
Expert Solution
![](/static/compass_v2/shared-icons/check-mark.png)
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 2 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
Recommended textbooks for you
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
![Concepts of Database Management](https://www.bartleby.com/isbn_cover_images/9781337093422/9781337093422_smallCoverImage.gif)
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
![Prelude to Programming](https://www.bartleby.com/isbn_cover_images/9780133750423/9780133750423_smallCoverImage.jpg)
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
![Sc Business Data Communications and Networking, T…](https://www.bartleby.com/isbn_cover_images/9781119368830/9781119368830_smallCoverImage.gif)
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY