PLEASE USE PYTHON SPYDER 1 Output a brief description of the

PLEASE USE PYTHON SPYDER

1) Output a brief description of the game of hangman and how to play.

2) Ask the user to enter the word or phrase that will be guessed (have a friend enter the phrase for you if you want to be surprised). Error check: repeatedly ask for a word or phrase until the input is letters and spaces.

3) Output the appropriate number of dashes and spaces to represent the phrase. Dashes are placeholders for letters.

4) Continuously read guesses of a letter from the user and replace the corresponding dashes if the letter is in the word (replace all occurrences, upper and lower case, of the letter), otherwise report that the user has made an incorrect guess. Error check: only accept letters and spaces. An incorrect guess is counted as a guess, but a guess that is not letters and spaces is not counted as a guess. If a guess is more than one letter, it is assumed to be a guess of the whole phrase: if the match is perfect (independent of case), the game is won; if not, the game is over as a loss.

5) Each turn you will display the phrase as dashes but with any already-guessed letters filled in, as well as which letters have been incorrectly guessed so far and how many guesses the user has remaining. Case of original input must be preserved, e.g. an upper-case letter in word/phrase must always be displayed in upper case even if the user guessed using a lower-case letter.

6) Your program should allow the user to make a total of k=6 guesses. After the 6th guess, the game is either won with a correct guess or the game ends as a loss.

7) One run of the program plays the game once. Do not have a loop to restart the game

indenting can be confusing so if you can use a code to copy of a screenshot that would help! Thank you!

Solution

import random

def main():

welcome = [\'hello ,Welcome to Hangman! A word will be chosen at random and\',

\'you must try to guess the word correctly letter by letter\',

\'before you run out of attempts. Good luck!\'

]

for line in welcome:

print(line, sep=\'\ \')

#here setting up the play_again loop

play_again = True

while play_again:

# then set up the game loop

words = [\"hangman\", \"cheggs\", \"bottles\", \"bodysoap\", \"brushing\",

\"computer\", \"python\", \"program\", \"glasses\", \"sweatshirt\",

\"sweatpotato\", \"mangoes\", \"friends\", \"clocks\", \"biology\",

\"algebra\", \"sunset\", \"knives\", \"apples\", \"shampoo\"

]

chosen_word = random.choice(words).lower()

player_guess = None # will hold the players guess

guessed_letters = [] # a list of letters guessed so far

word_guessed = []

for letter in chosen_word:

word_guessed.append(\"-\") # create an unguessed, blank version of the word

joined_word = None # joins the words in the list word_guessed

HANGMAN = (

\"\"\"

-----

| |

|

|

|

|

|

|

|

--------

\"\"\",

\"\"\"

-----

| |

| 0

|

|

|

|

|

|

--------

\"\"\",

\"\"\"

-----

| |

| 0

| -+-

|

|

|

|

|

--------

\"\"\",

\"\"\"

-----

| |

| 0

| /-+-

|

|

|

|

|

--------

\"\"\",

\"\"\"

-----

| |

| 0

| /-+-\\

|

|

|

|

|

--------

\"\"\",

\"\"\"

-----

| |

| 0

| /-+-\\

| |

|

|

|

|

--------

\"\"\",

\"\"\"

-----

| |

| 0

| /-+-\\

| |

| |

|

|

|

--------

\"\"\",

\"\"\"

-----

| |

| 0

| /-+-\\

| |

| |

| |

|

|

--------

\"\"\",

\"\"\"

-----

| |

| 0

| /-+-\\

| |

| |

| |

| |

|

--------

\"\"\",

\"\"\"

-----

| |

| 0

| /-+-\\

| |

| |

| | |

| |

|

--------

\"\"\",

\"\"\"

-----

| |

| 0

| /-+-\\

| |

| |

| | |

| | |

|

--------

\"\"\")

print(HANGMAN[0])

attempts = len(HANGMAN) - 1

while (attempts != 0 and \"-\" in word_guessed):

print((\"\ You have {} attempts remaining\").format(attempts))

joined_word = \"\".join(word_guessed)

print(joined_word)

try:

player_guess = str(input(\"\ Please select a letter between A-Z\" + \"\ > \")).lower()

except: # check valid input

print(\"That is not valid input. Please try again.\")

continue

else:

if not player_guess.isalpha(): # check the input is a letter. Also checks an input has been made.

print(\"That is not a letter. Please try again.\")

continue

elif len(player_guess) > 1: # check the input is only one letter

print(\"That is more than one letter. Please try again.\")

continue

elif player_guess in guessed_letters: # check it letter hasn\'t been guessed already

print(\"You have already guessed that letter. Please try again.\")

continue

else:

pass

guessed_letters.append(player_guess)

for letter in range(len(chosen_word)):

if player_guess == chosen_word[letter]:

word_guessed[letter] = player_guess # replace all letters in the chosen word that match the players guess

if player_guess not in chosen_word:

attempts -= 1

print(HANGMAN[(len(HANGMAN) - 1) - attempts])

if \"-\" not in word_guessed: # no blanks remaining

print((\"\ Congratulations! {} was the word\").format(chosen_word))

else: # loop must have ended because attempts reached 0

print((\"\ Unlucky! The word was {}.\").format(chosen_word))

print(\"\ Would you like to play again?\")

response = input(\"> \").lower()

if response not in (\"yes\", \"y\"):

play_again = False

if __name__ == \"__main__\":

main()

PLEASE USE PYTHON SPYDER 1) Output a brief description of the game of hangman and how to play. 2) Ask the user to enter the word or phrase that will be guessed
PLEASE USE PYTHON SPYDER 1) Output a brief description of the game of hangman and how to play. 2) Ask the user to enter the word or phrase that will be guessed
PLEASE USE PYTHON SPYDER 1) Output a brief description of the game of hangman and how to play. 2) Ask the user to enter the word or phrase that will be guessed
PLEASE USE PYTHON SPYDER 1) Output a brief description of the game of hangman and how to play. 2) Ask the user to enter the word or phrase that will be guessed
PLEASE USE PYTHON SPYDER 1) Output a brief description of the game of hangman and how to play. 2) Ask the user to enter the word or phrase that will be guessed
PLEASE USE PYTHON SPYDER 1) Output a brief description of the game of hangman and how to play. 2) Ask the user to enter the word or phrase that will be guessed
PLEASE USE PYTHON SPYDER 1) Output a brief description of the game of hangman and how to play. 2) Ask the user to enter the word or phrase that will be guessed

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site