Skip to content

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 

Repository files navigation

🎮 Hangman Game using Python

A simple command-line Hangman Game built using Python. The player has to guess a randomly selected word one letter at a time. The player gets 6 chances to guess the word correctly.

This project is beginner-friendly and demonstrates important Python concepts such as loops, conditional statements, lists, strings, user input, and the random module.

📌 Project Description

The Hangman Game randomly selects a word from a predefined list. The selected word is initially displayed as underscores (_).

The player enters one letter at a time. If the letter exists in the word, it is revealed in its correct position. If the letter is incorrect, the player loses one chance.

The game continues until:

  • 🎉 The player correctly guesses the complete word, or
  • 💀 The player uses all 6 chances.

✨ Features

  • 🎲 Random word selection
  • 🔤 Letter-by-letter guessing
  • ❤️ 6 chances for each game
  • ⚠️ Prevents repeated letter guesses
  • ✅ Displays correct guesses
  • ❌ Shows remaining chances after wrong guesses
  • 🎉 Win detection
  • 💀 Game-over detection
  • 🖥️ Simple command-line interface

🛠️ Technologies Used

  • Python 3
  • random module
  • Lists
  • Strings
  • while loop
  • for loop
  • if-else conditions
  • User input

📂 Project Structure

Hangman-Game/
│
├── hangman.py
└── README.md

🚀 How to Run

1. Clone the Repository

git clone https://github.com/your-username/Hangman-Game.git

2. Open the Project Folder

cd Hangman-Game

3. Run the Game

python hangman.py

🎯 How to Play

  1. Start the Python program.
  2. A random word will be selected automatically.
  3. The word will be displayed using underscores.
  4. Enter one letter at a time.
  5. If your guess is correct, the letter will be revealed.
  6. If your guess is wrong, you lose one chance.
  7. You have a maximum of 6 wrong guesses.
  8. Guess the complete word before your chances run out to win.

💻 Example Gameplay

🎮 Welcome to Hangman Game!
Guess the word letter by letter.

Word: _ _ _ _ _ _
Enter a letter: p

✅ Correct guess!

Word: p _ _ _ _ _
Enter a letter: y

✅ Correct guess!

Word: p y _ _ _ _
Enter a letter: z

❌ Wrong guess! Chances left: 5

Winning Example

Word: p y t h o n

🎉 Congratulations! You guessed the word: python

Losing Example

❌ Wrong guess! Chances left: 0

💀 Game Over! The word was: programming

🧠 How the Game Works

1. Select a Random Word

The random.choice() function selects one word from the predefined list:

words = ["python", "developer", "hangman", "programming", "computer"]
word = random.choice(words)

2. Hide the Word

The selected word is represented using underscores:

display_word = ["_"] * len(word)

3. Take User Input

The player enters a letter:

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

4. Check the Guess

The program checks whether the guessed letter exists in the selected word.

5. Update the Word

If the guess is correct, the corresponding position in the hidden word is revealed.

6. Reduce Chances

For every incorrect guess, the number of chances decreases by one.

7. Check the Result

The game checks whether:

  • All letters have been guessed → Player wins 🎉
  • Chances reach zero → Player loses 💀

📚 Python Concepts Learned

This project helps beginners understand:

  • Random number/module usage
  • Lists
  • String operations
  • User input
  • if, elif, and else
  • while loops
  • for loops
  • Conditional logic
  • Basic game development
  • Managing game state

🔮 Future Enhancements

The game can be improved by adding:

  • 🖼️ ASCII Hangman graphics
  • 📚 Larger word dictionaries
  • 🎯 Difficulty levels
  • 🏆 Score system
  • 🔄 Play-again option
  • ⏱️ Timer
  • 👥 Two-player mode
  • 💡 Hint system
  • 🏅 High-score tracking
  • 🖥️ Graphical User Interface using Tkinter

🎯 Project Objectives

The main objective of this project is to build a simple interactive game while practicing fundamental Python programming concepts.

It is suitable for:

  • Beginners learning Python
  • College mini-projects
  • Python practice
  • GitHub portfolios
  • Understanding loops and conditional statements

About

Python Hangman Game

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages