0% found this document useful (0 votes)
8 views8 pages

Hangman

The Hangman Game is a Python project that recreates the classic word-guessing game where players guess letters to uncover a hidden word. The game utilizes programming concepts such as string manipulation, loops, and conditionals, and includes a predefined list of words and a hangman drawing that progresses with incorrect guesses. The project aims to enhance programming skills and logical thinking through an interactive experience.

Uploaded by

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

Hangman

The Hangman Game is a Python project that recreates the classic word-guessing game where players guess letters to uncover a hidden word. The game utilizes programming concepts such as string manipulation, loops, and conditionals, and includes a predefined list of words and a hangman drawing that progresses with incorrect guesses. The project aims to enhance programming skills and logical thinking through an interactive experience.

Uploaded by

Deepti Govindu
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

PYTHON PROJECT

GAME: HANGMAN

INTRODUCTION
The Hangman Game is a classic word-guessing game that challenges players to
uncover a hidden word by guessing one letter at a time. This Python project
recreates the traditional Hangman experience using simple programming logic,
loops, and conditionals.
In this project, the computer randomly selects a word from a predefined list, and
the player must guess the letters within a limited number of attempts. For every
incorrect guess, a part of the hangman figure is drawn — bringing the player
closer to losing. The game continues until the player either correctly guesses the
word or runs out of chances.
The main goal of this project is to demonstrate fundamental Python
programming concepts such as:
 String manipulation
 Conditional statements and loops
 Lists and random selection
 User input and output
 Basic game logic and control flow
This project not only helps strengthen programming skills but also introduces
players to logical thinking and problem-solving through an interactive and
enjoyable game.

INPUT
import random

words = ("Cat", "Dog", "Hat", "Sun", "Tree", "Book", "Fish", "Star", "Ball", "Bird",
"Blue", "Door", "Cake", "Apple",
"Truck", "Chair", "Desk", "Rain", "Bear", "Ship", "Duck", "Rock", "Coin",
"King", "Ring", "Road", "Moon",
"Bell", "Gold", "Snow", "Wind", "Pond", "Leaf", "Girl", "Boy", "Car", "Sky",
"Red", "Green", "Cold", "Love",
"Home", "Jump", "Kind", "Game", "Boat", "Smile", "Food", "Basket",
"Rocket", "Jungle", "Quilt", "Market",
"Forest", "Spirit", "Wonder", "Guitar", "Orange", "Secret", "Dragon",
"Castle", "Bridge", "Garden", "Pirate",
"Animal", "Candle", "Elephant", "Subway", "Ocean", "Friend", "Spring",
"Bottle", "Copper", "Giraffe", "Summer",
"Pocket", "Jacket", "Fancy", "Monster", "Falcon", "Planet", "Ticket", "Robot",
"Banana", "Soccer", "Bishop",
"Camera", "Double", "Garlic", "Quiz", "Jovial", "Zephyr", "Mystique",
"Cryptic", "Psyche", "Oxygen",
"Knapsack", "Bizarre", "Pixel", "Glyph", "Waltz", "Exodus", "Phantom",
"Fluorescent", "Gazebo", "Rhythm",
"Vortex", "Galaxy", "Jackal", "Memento", "Zombie", "Sphinx", "Haphazard",
"Glimpse", "Acoustic", "Quixotic",
"Labyrinth", "Espresso", "Equinox", "Complex", "Fjord", "Jigsaw", "Kiosk",
"Nebula", "Scaffold", "Ubiquitous",
"Tsunami", "Vertex", "Abscond", "Plasma", "Enigma", "Whimsical", "Onyx",
"Junction", "Zealous", "Griffin",
"Crypt", "Jubilee", "Radar", "Mirror", "Mistake", "Random", "Barber",
"Bandana", "Ladder", "Debate", "Mimic",
"Puzzle", "Hammer", "Banner", "Dinner", "Ribbon", "Render", "Babble",
"Desert", "Memory", "Modern", "Tender",
"Paddle", "Middle", "Mumble", "Timber", "Magnet", "Broaden", "Cannon",
"Bender", "Fumble", "Lumber", "Manner",
"Member", "Number", "Timid", "Saddle", "Matter", "Muddle", "Bonnet",
"Winter", "Sonder", "Rumble", "Center",
"Summit", "Kangaroo", "Dolphin", "Penguin", "Parrot", "Zebra", "Cheetah",
"Octopus", "Buffalo", "Lasagna",
"Muffin", "Cabbage", "Yogurt", "Sausage", "Chili", "Lobster", "Pumpkin",
"Waffle", "Almond", "Rainbow",
"Tornado", "Hurricane", "Thunder", "Volcano", "Blizzard", "Cyclone",
"Eclipse", "Sunshine", "Avalanche")

hangman_art = {
0: (" ",
" ",
" "),
1: (" o ",
" ",
" "),
2: (" o ",
" | ",
" "),
3: (" o ",
"/| ",
" "),
4: (" o ",
"/|\\",
" "),
5: (" o ",
"/|\\",
"/ "),
6: (" o ",
"/|\\",
"/ \\")
}

def display_man(wrong_guesses):
print('************')
for line in hangman_art[wrong_guesses]:
print(line)
print('************')

def display_hint(hint):
print(" ".join(hint))

def display_answer(answer):
print(" ".join(answer))

def main():
answer = [Link](words).lower()
hint = ["_"] * len(answer)
wrong_guesses = 0
guessed_letters = set()

while True:
display_man(wrong_guesses)

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

if len(guess) != 1 or not [Link]():


print("Invalid input")
continue

if guess in guessed_letters:
print(f"'{guess}' is already guessed")
continue

guessed_letters.add(guess)

if guess in answer:
for i in range(len(answer)):
if answer[i] == guess:
hint[i] = guess
else:
wrong_guesses += 1

if "_" not in hint:


display_man(wrong_guesses)
print("Answer:", answer)
print("--- YOU WIN! ---")
break
if wrong_guesses >= 6:
display_man(wrong_guesses)
print("Answer:", answer)
print("--- YOU LOSE! ---")
break

if __name__ == "__main__":
main()

OUTPUT
************

************
_________
Enter a letter: r
************
o

************
_________
Enter a letter: o
************
o
|

************
_________
Enter a letter: a
************
o
|

************
_______a_
Enter a letter: e
************
o
/|

************
_______a_
Enter a letter: c
************
o
/|

************
______ca_
Enter a letter: t
************
o
/|\

************
______ca_
Enter a letter: s
************
o
/|\

************
____s_ca_
Enter a letter: a
'a' is already guessed
************
o
/|\

************
____s_ca_
Enter a letter: d
************
o
/|\
/
************
____s_ca_
Enter a letter: h
************
o
/|\
/
************
_h__s_ca_
Enter a letter: k
************
o
/|\
/\
************
Answer: whimsical
--- YOU LOSE! ---

You might also like