Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

python 3.6 Requriements Submit only the files requested Print all floats to 2 decimal points unless stated otherwise Restrictions No global variables may be used

python 3.6

Requriements

Submit only the files requested

Print all floats to 2 decimal points unless stated otherwise

Restrictions

No global variables may be used

NEW: The only code that may appear outside of a function are function definitions and function calls

NEW: You may not import any modules

Description

You will be implementing the game hangman. In hangman one player chooses a secret word and the other player guesses letters. Each time the second player guesses a correct letter, all instances of that letter in the secret word are revealed. If the second player guesses a letter that is not in the word, then a portion of the hangman is drawn. The game ends once the entire hangman is drawn or the second player guesses all of the letters that are in the word. You can play hangman here.

Details

The second player has 7 guesses to guess the correct word

After each incorrect guess the pieces of the hangman are drawn in the following order: rope, head, torso, left arm, right arm, left leg, and right leg

At the beginning of the game the first player should be asked to enter the secret word.

The letters in the secret word should be displayed as ? until the user guesses them

After the secret word is entered 30 new lines should be printed to the screen to hide the secret word

Don't forget you can multiply a string by a number here to save yourself some typing

At the beginning of each round you should display the following in this order

The hanged man

The partially guessed secret word

The characters guessed so far in sorted order

If the user guesses a letter they have already guessed they should be told they already guessed that letter and be asked to enter a new guess

These guesses should not be counted against the user

Assumptions

Input will not always be valid

If invalid input is received your program should continue to ask for more input until a valid value is entered

Valid Values for Input

Secret Word: Any string that does not contain ? or whitespace characters

Guess: a single letter that has not already been guessed

Strip whitespace from the guess before checking it

If only whitespace is entered it is treated like the user didn't enter anything

Hints

Use functions to help you solve this problem. Breaking it down into steps and and turning each step into a function will make solving this problem a lot easier. Some functions I hade were

get_secret_word

get_guess

is_game_over

display_hangman

display_guesses

Examples

In the examples below user input has been underlined. For space reasons the 30 new lines aren't shown.

Example 1

Please enter a word to be guessed that does not contain ? or white space: hello ????? So far you have guessed: Please enter your next guess: h h???? So far you have guessed: h Please enter your next guess: t | h???? So far you have guessed: h, t Please enter your next guess: y | 0 h???? So far you have guessed: h, t, y Please enter your next guess: t You already guessed the character: t Please enter your next guess: y You already guessed the character: y Please enter your next guess: hi You can only guess a single character. Please enter your next guess: joke You can only guess a single character. Please enter your next guess: l | 0 h?ll? So far you have guessed: h, l, t, y Please enter your next guess: u | 0 | h?ll? So far you have guessed: h, l, t, u, y Please enter your next guess: ( | 0 /| h?ll? So far you have guessed: (, h, l, t, u, y Please enter your next guess: e | 0 /| hell? So far you have guessed: (, e, h, l, t, u, y Please enter your next guess: o You correctly guessed the secret word: hello

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

Intranet And Web Databases For Dummies

Authors: Paul Litwin

1st Edition

0764502212, 9780764502217

More Books

Students also viewed these Databases questions

Question

What are the main objectives of Inventory ?

Answered: 1 week ago

Question

Explain the various inventory management techniques in detail.

Answered: 1 week ago

Question

Why do HCMSs exist? Do they change over time?

Answered: 1 week ago