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. Projects posted are only 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 fill out the form. Please provide a valid email address and we'll get back to you in less than 24 hours. We will be sending an invoice through PayPal upon confirmation. We are a non profit organization however we need an amount to keep this organization running, and to be able to complete our research and development.