Background

Jeff has had a lot of time on his hands. He has decided to automate one of his favourite games hangman.

Task

Your task is to create a simple hangman game. Your program should perform the following tasks:

  • Select a word at random from an array
  • Ask the user if they would like to guess the word or request a letter
  • If the user guesses the word
    • Advise them if they got it correct or not (if correct, game ends)
    • Subtract one attempt from their total allowed attempts
  • If the user requests a letter
    • Reveal all instances of that letter in the series
    • Subtract one attempt from their total allowed attempts

Example Output (input is in bold)

$ python hangman.py

Word contains 4 letters
You have 5 attempts remaining

_ _ _ _

Enter word to solve, or letter to reveal: a

You have 4 attempts remaining

_ a _ _

Enter word to solve, or letter to reveal: t

You have 3 attempts remaining

_ a t _

Enter word to solve, or letter to reveal: t

You have 3 attempts remaining

_ a t _

Enter word to solve, or letter to reveal: z

You have 2 attempts remaining

_ a t _

Enter word to solve, or letter to reveal: c

You have 1 attempts remaining

c a t _

Enter word to solve, or letter to reveal: cats

Congratulations, you discovered the word!
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.