Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

we are using python 1) [20 marks] Write a function named enter_guess which will take the list of letters already guessed (initially, this will be

we are using python
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
1) [20 marks] Write a function named enter_guess which will take the list of letters already guessed (initially, this will be an empty list). The function asks the user to enter a single letter and error checks to ensure that exactly 1 alphabetic character is entered. It will also check to see if the letter has already been guessed. The single letter will be returned. For example: > guess = enter_guess(guess_list) Enter a letter: 3 Please enter 1 and only 1 letter: \% Please enter 1 and only 1 letter: b You have already guessed that letter. Try another: c You have already guessed that letter. Try another: ty Please enter 1 and only 1 letter: d > print(guess) d 2) [10 marks] Write a function called get word which takes a list of words and randomly returns one word. You must use either random. randint or random. choices. For example: target = get_word(words) student 3) [60 marks] Write a function called hangman which takes a string (a target word) as a parameter. This function displays the initial gallows and the number of underscores in the target word. As long as the target word has not been guessed or the user has not incorrectly guessed 7 letters, get a letter from the user (call enter_guess), if the letter is not in the target word, increment a counter that keeps track of the number of incorrect guesses and add one more piece to the gallows. If the letter is in the target word, replace the underscore in the location of the letter, with the letter. Then display the underscores (possibly including letters) and the letters guessed (sorted alphabetically). Once the target word has been guessed or the user has incorrectly guessed 7 letters, display the results. See screenshots at end. The join method (a string method) can be very helpful in this function. It takes an iterable (like a list) as a parameter and produces a string with the initial string between each of the list items, e.g.' '. join (['a', 'b', ' c ', ' d ' ] ) would produce the string 'a b c d'. Note: The Python style guide states that functions should be no longer than 20 lines of code (a couple more is ok). This function will require much more than 20 lines. Therefore, it will be helpful to write helper functions that do parts of what's required, e.g. creating the initial gallows and displaying the results. 4) [10 marks] Write a function named tha in which takes no parameters. This function calls get_ words to get a target word and then uses this to call the hangman function. This function returns None. See the following pages for examples of the game being played. Here is an example of a complete game with the player winning: mainO Enter a letter: e 1 1 1 1 -e letters guessed: e Enter a letter: t 1 _e letters guessed: e,t Enter a letter: a 1 a_e letters guessed: a,e,t Enter a letter: e You have already guessed that letter. Try another: s nainO Enter a letter: e - le___ letters guessed: Enter a letter: a Enter a tet Ce letters guessed: e, q Enter a letter: f 110 _e. letters guessed: e,f,q Enter o letter: z 11Inter...10 _ e letters guessed: e,f,q,z Enter a letter: y inter a let

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions