Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PLEASE CODE THIS USING PYTHON AND USE AS BEGINNER/BASIC FUNCTIONS AS POSSIBLE (please don't use def() or anything more advanced like that) Objective: Develop a

PLEASE CODE THIS USING PYTHON AND USE AS BEGINNER/BASIC FUNCTIONS AS POSSIBLE (please don't use def() or anything more advanced like that)

Objective: Develop a program that allows students to play hangman with a list of words that you will create! Each turn you will ask a letter to be used, play until you find the secret word and count how many mistakes you have. A user will get a total of 7 mistakes before you stop the loop and then tell the user the word. You must ask again if the user wants to play again, you must provide a different word.

TODO:

Begin by creating a program called HangMan.py. Be sure to include a header comment at the top of the file that includes your name, the date, the assignment and a brief description of the program.

Declaring variables: Declare the following variables, keeping in mind that some will be initialized using the users input (below):

words: //#a list of minimum 20 words of at least length 6 characters, and lower case that you will declare, this list will not change throughout the program.

word//#randomly select one of the words in your list words, every new round the program should select the word randomly

misses//#variable that will store the number of times the letter used was not in the word. (tip: add 1 whenever a letter is not in the secret word)

asterisk //# variable that will display the secret word as a sequence of *, of the same length as the secret word. (i.e. hello > *****)

letter //# input from the user, you will use this to check if it is inside the word and then if it is change the asterisk for the corresponding letter.

alpha //# variable where you will store the letters

keepPlaying //# input from the user, use this variable to check if you need to play the game again, and reinitialize all the variables, so the game can continue.

The steps that you should follow, for the program to run are:

1. Check if the input letter is in the list of already used letters, if it is inside the list, you should output a prompt telling the user that the letter has been used, otherwise add the letter to the list

2. If the letter has not been used, it is time to check if the letter is in the word, and replace all the asterisks that correspond to the place of the letter in the word.

3. Check if we have replaced all the asterisks in the secret word, if so show the word and the number of missed attempts, then ask the user if they want to play again.

4. If they want to play again some variables need to initialize again so the game can continue

The output of the program should look like this:

******* enter the letter: a

a****** enter the letter: t

att***t enter the letter: e

atte**t enter the letter: a

a was already used

atte**t enter the letter: m

attem*t enter the letter: p

The word was: attempt with 0 missed attempts

Do you want to play again? yes/no: yes

***** enter the letter: h

h**** enter the letter: a

h**** enter the letter: l

h*ll* enter the letter: o

h*llo enter the letter: t

h*llo enter the letter: e

The word was: hello with 2 missed attempts

Do you want to play again? yes/no: no

Pro tip:

Strings are immutable objects in python, thus it is really difficult to change values in the string, use the python list() method to transform it into a list, where you can access by index and change with ease, after the changes use the join() method to transform back into strings. (this is optional you can find a different way)

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

Oracle RMAN For Absolute Beginners

Authors: Darl Kuhn

1st Edition

1484207637, 9781484207635

More Books

Students also viewed these Databases questions