Tab 1
PM SHRI KENDRIYA VIDYALAYA
PATTOM, TRIVANDRUM
CLASS XI
COMPUTER SCIENCE PROJECT
HANGMAN GAME PROGRAM
DEPARTMENT OF COMPUTER SCIENCE
2024-25
DEPARTMENT OF COMPUTER SCIENCE
KENDRIYA VIDYALAYA
PATTOM, TRIVANDRUM
COMPUTER SCIENCE PROJECT
2024-25
ROLL NO:
This is certified to be the Bonafide record of the work done by
_ADITHI RAMESH of class XI Computer Science in the computer
lab during the year 2023-24.
Submitted for the Class XI Session Ending Examination-24 to be
held on ………………… at KENDRIYA VIDYALAYA
KANJIKODE WEST, PALAKKAD.
Principal Teacher In charge
Internal Examiner External Examiner
ACKNOWLEDGEMENT
I express my sincere gratitude to our respected
Principal for providing the opportunity to
delve into the realm of computer science.
Special thanks to our dedicated subject
teacher, Arun Sir, whose guidance and
expertise have been instrumental in shaping
this project. Your unwavering support has
enriched our learning experience and made
this endeavor possible.
INDEX
1.Introduction
2.System Requirements
3.Source Code
4.Output
5.Bibliography
Introduction to the Hangman Game
Welcome to our Python project!
This is a classic Hangman game, where players
guess a hidden word one letter at a time before
running out of attempts. With each wrong guess,
a Hangman figure gradually appears, adding
suspense to the game.
Designed for an interactive and user-friendly
experience, this text-based game ensures
smooth gameplay with clear prompts and simple
inputs. Whether you're learning Python or just
love word games, this project offers a fun and
engaging challenge!
-Can you guess the word before the Hangman
is fully drawn? Let’s play!
SOURCE CODE
#HANGMAN GAME!!
import random
# Word list
words = ["python", "hangman", "computer", "keyboard",
"developer", "internet"]
# Hangman drawing stages
hangman_stages = [
"""
-----
| |
| O
| /|\\
| / \\
|
""",
"""
-----
| |
| O
| /|\\
| /
|
""",
"""
-----
| |
| O
| /|\\
|
|
""",
"""
-----
| |
| O
| /|
|
|
""",
"""
-----
| |
| O
| |
|
|
""",
"""
-----
| |
| O
|
|
|
""",
"""
-----
| |
|
|
|
|
"""
]
# Choose a random word
word = random.choice(words)
guessed_letters = []
attempts = len(hangman_stages) - 1 # 6 lives
print("\n 🎮
Welcome to Hangman! 🎮 ")
print("The word has", len(word), "letters.")
# Game loop
while attempts > 0:
# Show hangman figure
print(hangman_stages[attempts])
# Show the word with guessed letters
display_word = ""
for letter in word:
if letter in guessed_letters:
display_word += letter + " "
else:
display_word += "_ "
print("\nWord:", display_word.strip())
print(f"Lives left: {attempts}")
# Taking user input
guess = input("Guess a letter: ").lower()
# Validating input
if len(guess) != 1 or not guess.isalpha():
❌
print(" Invalid input! Enter a single letter.")
continue
# Check if letter was already guessed
⚠️
if guess in guessed_letters:
print(" You've already guessed that letter!")
continue
# Add the guessed letter to the list
guessed_letters.append(guess)
# Check if the letter is in the word
✅
if guess in word:
print(" Correct guess!")
else:
❌
attempts -= 1 # Reduce life for wrong guess
print(" Wrong guess!")
# Check if the player has guessed the entire word
🎉
if all(letter in guessed_letters for letter in word):
print(f"\n You won! The word was '{word}'.")
break
else:
# Show full hangman figure when the player loses
print(hangman_stages[0])
💀 You lost! The word was '{word}'. Better luck next
print(f"\n
time!")
OUTPUT
🎮 Welcome to Hangman! 🎮
The word has 7 letters.
-----
| |
|
|
|
|
Word: _ _ _ _ _ _ _
Lives left: 6
❌
Guess a letter: e
Wrong guess!
-----
| |
| O
|
|
|
Word: _ _ _ _ _ _ _
Lives left: 5
✅
Guess a letter: a
Correct guess!
-----
| |
| O
|
|
|
Word: _ a _ _ _ a _
Lives left: 5
✅
Guess a letter: h
Correct guess!
-----
| |
| O
|
|
|
Word: h a _ _ _ a _
Lives left: 5
✅
Guess a letter: g
Correct guess!
-----
| |
| O
|
|
|
Word: h a _ g _ a _
Lives left: 5
❌
Guess a letter: k
Wrong guess!
-----
| |
| O
| |
|
|
Word: h a _ g _ a _
Lives left: 4
✅
Guess a letter: m
Correct guess!
-----
| |
| O
| |
|
|
Word: h a _ g m a _
Lives left: 4
❌
Guess a letter: jk
Invalid input! Enter a single letter.
-----
| |
| O
| |
|
|
Word: h a _ g m a _
Lives left: 4
⚠️
Guess a letter: m
You've already guessed that letter!
-----
| |
| O
| |
|
|
Word: h a _ g m a _
Lives left: 4
✅
Guess a letter: n
Correct guess!
🎉 You won! The word was 'hangman'.
=== Code Execution Successful ===
SYSTEM REQUIREMENTS
System Requirements for Running the
Hangman Game
The system requirements for running this Hangman game in
Python are minimal, as Python is a lightweight and
cross-platform language.
Software Requirements:
1️⃣ Python Interpreter
● Python 3.6 or higher is required.
● Download from the official site: https://www.python.org/
● Works on Windows, macOS, and Linux.
2️⃣ Code Editor (Optional, but Recommended)
● You can use any text editor or IDE, such as:
○ VS Code
○ PyCharm
○ IDLE
Operating System Requirements:
● Windows: Windows 7, 8, 10, 11
● macOS: macOS 10.12 (Sierra) or later
● Linux: Any major distribution (Ubuntu, Fedora, Debian,
etc.)
Hardware Requirements:
● Processor: Any modern processor (Intel/AMD)
● RAM: Minimum 1 GB (Recommended: 2 GB+)
● Storage: Less than 100 MB required for Python
installation
● Graphics: No special GPU needed (text-based program)
Final Verdict
This Hangman game is lightweight and runs smoothly on
almost any computer. You don’t need a high-end PC—just
install Python and start playing!
Bibliography
To develop this Hangman game, we referred to
various resources for Python programming
concepts and best practices. Below are the key
sources of information used:
●google.com & youtube.com- for reference
●Online Python Compiler- for doing trial and
error of the source code
🔗 https://www.programiz.com
●CBSE Python Textbook (Class 11) –
Reference for Python basics and structured
programming concepts.
These sources helped in designing an efficient,
interactive, and user-friendly Hangman game