Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hangman Game, Mini Project Assignment Required: Write your own Python Module to implement Hangman game. Project: Hangman We're going to write the game of Hangman.

image text in transcribedimage text in transcribedimage text in transcribed

Hangman Game, Mini Project Assignment Required: Write your own Python Module to implement Hangman game. Project: Hangman We're going to write the game of Hangman. You only have to pass in the Hangman code. Create a new file hangman.py. We're going to start by storing the state of the game in variables at the top of the program. The state is a complete description of all the information about the game. The state would be: -The current player - How many stones are in the pile, or lives For Hangman, we need to store 3 pieces of information: secret_word: The word they are trying to guess (string). letters_guessed: The letters that they have guessed so far (list). mistakes_made: The number of incorrect guesses they've made so far (int). You can name these something else if you'd like, but use a descriptive name. Max_guesses = 6. The program must provide the following output. Please watch the video explanation for more information. Olive = 6 show that the word has 5 letter and that no misses and still has 6 guesses _yb_r (c, x, t, g) live = 2 _yb_r [c, xt, g, f] live = 1 cyber [c, x, t, g, f, s] winner cyber [c, x, t, g, f, s, v,r] lost Play again? Deliverable: Upload your Python file "hangman.py" onto Canvas. Example code: import random asr # steps to select a random word from words.txt file with open("words.txt") as file: data = file.read().split() number = r.randint(0, len(data) word = data[number] # create a list of underscore. # it contains exactly same number of underscore as the length of our random word lines = 1) for i in word: lines.append('_') # counter variable is used to track number of wrong letters. # a user can make if it is 6 then terminate the program and print message counter = 0 while True: letter =input(' Guess your letter :') if letter in word: for i in range(0, len(word)): if word[i] == letter: lines[i] = letter else: #letter is not in the word counter += 1 # print the word with inserted letters for i in lines: printi, end="") #check letters remained in the list cnt = "".join(lines).count('_') if cnt == 0 or counter == 6: break # end of while loop if counter >= 6: print(" You lost") else: print(" You WON")

Step by Step Solution

There are 3 Steps involved in it

Step: 1

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

Harness The Power Of Big Data The IBM Big Data Platform

Authors: Paul Zikopoulos, David Corrigan James Giles Thomas Deutsch Krishnan Parasuraman Dirk DeRoos Paul Zikopoulos

1st Edition

0071808183, 9780071808187

More Books

Students also viewed these Databases questions