2024-2025
1|Page
BONAFIDE CERTIFICATE
Certified to be the bonafide project work done
by …………………………………………………………………………………..….. of STD - XII in
the COMPUTER SCIENCE laboratory of S.B.O.A. School and Junior College,
Chennai - 600 101 during the year 2024 - 2025.
Date: Teacher-in-Charge
Submitted for the Senior Secondary Examination held in the year
2024 - 2025 at S.B.O.A. School and Junior College. Chennai - 600 101.
External Examiner Internal Examiner
2|Page
ACKNOWLEDGEMENT
I would like to express my special thanks of gratitude to
our school’s principal Mrs. Sharadha Ramamurthy, Vice
principal Mrs. M.V Mahalakshmi and our Computer
Science teacher Mrs. K. Bhavani for their valuable
guidance and support. I would also like to thank my
team members for their cooperation and support in
completing this project.
3|Page
HANGMAN GAME
COMPUTER SCIENCE PROJECT
4|Page
INDEX
TITLE PAGE NO
5|Page
OBJECTIVE
The primary objective of a Hangman game implemented in Python is
to provide an engaging and interactive way to guess a hidden word.
In detail:
1. Entertainment and Fun
The game is designed to be a simple yet challenging word-
guessing activity for players to enjoy.
2. Logical Thinking and Problem-Solving
Players need to think logically and strategically to guess letters
based on the clues (revealed letters and remaining attempts).
3. Skill Development
Encourages vocabulary enhancement as players guess words.
Improves memory and pattern recognition skills.
4. Coding Practice (if you're creating the game)
For developers, creating a Hangman game serves as:
A practice project: It helps in learning Python basics, such as
loops, conditionals, and string manipulation.
Algorithm development: Designing the game logic requires
handling user input, updating the display of guessed letters, and
checking winning/losing conditions.
Error handling: Ensuring the game handles invalid inputs
gracefully.
5. Educational Tool
In an educational setting, the game can be used to teach
spelling, word recognition, and language skills.
6|Page
SOURCE CODE
7|Page
import random
import math
class Hangman:
# Hangman game
# hang stage and rope figure
hang_figure = []
hang_figure.append(' +----+')
hang_figure.append(' |')
hang_figure.append(' |')
hang_figure.append(' |')
hang_figure.append(' |')
hang_figure.append(' |')
hang_figure.append('=======')
#man figure
8|Page
man_figure = {}
man_figure[0] = [' | |']
man_figure[1] = [' | |',' 0 |']
man_figure[2] = [' | |',' 0 |', ' |
|']
man_figure[3] = [' | |','\\0 |', ' |
|']
man_figure[4] = [' | |','\\0/ |', ' |
|']
man_figure[5] = [' | |','\\0/ |', ' |
|', '/ |']
9|Page
man_figure[6] = [' | |','\\0/ |', ' |
|', '/ \\ |']
man_figure[7] = [' | |',' 0/ |', '/|
|', '/ \\ |']
man_figure[8] = [' | |',' 0 |', '/|\\
|', '/ \\ |']
man_figure[9] = [' | |',' 0 |', '/|\\
|', '/ \\ |','DEAD |']
hangman = []
def __init__(self):
i, j = 1, 0
self.hangman.append(self.hang_figure[:
])
10 | P a g e
for ls in self.man_figure.values():
pic, j = self.hang_figure[:], 0
for m in ls:
pic[i + j] = m
j += 1
self.hangman.append(pic)
def print_hangman( self, index ):
for line in self.hangman[index]:
print(line)
def start (self):
print ("\nWelcome to hangman.
Please save a life guessing correct
11 | P a g e
word.[HINT:The category is
FRUITS!]\n")
# a list of words, selected a
random word
word =
random.choice(['apple','grapefruit','per
simmon','banana','orange','plum','hone
ydew','melon','peach','cantaloupe','ma
ngo','cherry','blackberry',
'pineapple','pear','kiwifruit','watermelo
n','grape','mulberry','kiwi','guava','jackf
ruit','papaya','pomegranate','currant',
'strawberry','apricot','elderberry','blue
berry','cranberry','gooseberry','raspber
ry','fig','date','lemon','avocado','olive',
12 | P a g e
'lime','passionfruit','tangerine','lychee','
dragonfruit','durian'])
#remaining turns
turns = len(word)*2
#store user input characters
guess = []
k=0
while ( turns >= 0 ) :
if ( turns == 0 ):
print ("Hey! you have killed a
man!,the word was",word,"!")
break
13 | P a g e
hint = [l if l in guess else "_" for l
in word]
print ("\nGuess the word : ",
end="")
print (" ".join(hint) )
print ("Turns left : ", turns )
if word == ("".join(hint) ) :
print ("\nThanks for saving a
life.")
break
else :
char = input ('\nEnter a
character : ')
if ( char in word ) :
14 | P a g e
guess.append(char)
else :
turns -= 1
k = 10 -
math.floor( 10*(turns/(len(word)*2)))
if k == (len(self.hangman)-1)
and turns == 1 :
k -= 1
self.print_hangman(k)
Hangman().start()
15 | P a g e
OUTPUT
16 | P a g e
GAME WON OUTPUT:
17 | P a g e
18 | P a g e
19 | P a g e
GAME LOST OUTPUT
20 | P a g e
21 | P a g e
22 | P a g e
BIBLIOGRAPHY
https://chatgpt.com/
https://www.geeksforgeeks.org/
https://www.youtube.com/
23 | P a g e