0% found this document useful (0 votes)
256 views6 pages

Hangman Game

The document explains the classic word guessing game of Hangman, providing the rules and instructions for playing. It details how a secret word is chosen and the player guesses letters, with incorrect guesses resulting in parts of a hangman figure being drawn. It also includes Python code to programmatically play the game.

Uploaded by

Chaitrali parab
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
256 views6 pages

Hangman Game

The document explains the classic word guessing game of Hangman, providing the rules and instructions for playing. It details how a secret word is chosen and the player guesses letters, with incorrect guesses resulting in parts of a hangman figure being drawn. It also includes Python code to programmatically play the game.

Uploaded by

Chaitrali parab
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

HANGMAN GAME

INTRODUCTION:
Welcome to Hangman, a classic word-guessing game where your goal
is to figure out the hidden word before it's too late! The rules are
simple:

1. A secret word is chosen, and its letters are represented by dashes.


2. You have a limited number of guesses to figure out the word.
3. Each time you guess a letter, if it's in the word, those letters are
revealed. If not, you lose one of your guesses.
4. Be careful! If you make too many incorrect guesses, you'll be
"hanged" and the game ends.

Are you ready to test your vocabulary skills and save the hangman
from his fate? Let's play!
HOW TO PLAY HANGMAN GAME ?
To play Hangman, follow these steps:
1. Setup: One player (the "host") thinks of a word and writes down a
dash for each letter of that word, representing the unknown letters.
For example, if the word is "apple", they would write "_ _ _ _ _".
2. Guessing: The other player (the "guesser") starts guessing letters
that they think might be in the word. They can guess one letter at a
time.
3. Revealing Letters: If the guessed letter is in the word, the host
reveals all occurrences of that letter in the word. For example, if the
guess is "p" and the word is "apple", the host would reveal the two
"p"s: "_ p p _ _".
4. Incorrect Guesses: If the guessed letter is not in the word, the host
starts drawing parts of the hangman as a penalty. Commonly, there are
6 parts to draw: head, body, left arm, right arm, left leg, and right leg.
5. Continuation: The guesser continues guessing letters until they
either correctly guess the word (filling in all the blanks) or make too
many incorrect guesses, resulting in the completion of the hangman
figure.
6. Outcome: The game ends when the guesser either successfully
guesses the word or the hangman is fully drawn. If the guesser guesses
the word correctly, they win. If the hangman is completed before the
word is guessed, the host wins.

Remember, the number of incorrect guesses allowed before the


hangman is completed varies, but it's typically around six. Let the
guessing begin!
CODE:
import random
def choose_word():
words = ["apple", "banana", "orange", "grape", "pineapple"]
return random.choice(words)

def display_word(word, guessed_letters):


display = ""
for letter in word:
if letter in guessed_letters:
display += letter

else:
display += "_"
return display

def hangman():
word = choose_word()
guessed_letters = []
attempts = 6

print("Welcome to Hangman!")
print("Try to guess the word.")
while attempts > 0:
print("\nAttempts left:", attempts)
print("Word:", display_word(word, guessed_letters))

guess = input("Enter a letter: ").lower()

if len(guess) != 1 or not guess.isalpha():


print("Please enter a single letter.")
continue

if guess in guessed_letters:
print("You've already guessed that letter.")
continue

guessed_letters.append(guess)

if guess not in word:


attempts -= 1
print("Incorrect guess!")
if attempts == 0:
print("Sorry, you lost. The word was:", word)
break
else:
print("Correct guess!")

if all(letter in guessed_letters for letter in word):


print("Congratulations, you guessed the word:", word)
break

play_again = input("Do you want to play again? (yes/no): ").lower()


if play_again == "yes":
hangman()

else:
print("Thanks for playing!")
hangman()
Output:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy