0% found this document useful (0 votes)
3 views

11205 CHANDANA GJ CS IP

The document presents a Computer Science investigatory project on the game 'Hangman' created by G J Chandana at The PSBB Millennium School. It includes an introduction to Python, program analysis, source code, and sample outputs demonstrating the game's functionality. The project aims to engage users in a fun and educational guessing game while showcasing programming concepts learned in class.
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)
3 views

11205 CHANDANA GJ CS IP

The document presents a Computer Science investigatory project on the game 'Hangman' created by G J Chandana at The PSBB Millennium School. It includes an introduction to Python, program analysis, source code, and sample outputs demonstrating the game's functionality. The project aims to engage users in a fun and educational guessing game while showcasing programming concepts learned in class.
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
You are on page 1/ 26

THE PSBB MILLENNIUM SCHOOL

GERUGAMBAKKAM, CHENNAI
COMPUTER SCIENCE INVESTIGATORY PROJECT

HANGMAN SUBMITTED BY
BONAFIDE G J CHANDANA
USN - 180146
ROLL NO. - 11205
XI - ‘B’
2024-2025

CERTIFICATE

This is to certify that the project entitled “HANGMAN” is a record of bonafide


work carried out by G J Chandana of class XI – ‘B’ in THE PSBB
MILLENNIUM SCHOOL, GERUGAMBAKKAM during the year 2024-25
in partial fulfilment of the requirements in COMPUTER SCIENCE prescribed
by CBSE.

Submitted for Senior Secondary Practical Examination held in THE


PSBB MILLENNIUM SCHOOL, GERUGAMBAKKAM at COMPUTER
SCIENCE LAB.

DATE: _________ PRINCIPAL

INTERNAL EXAMINER EXTERNAL


EXAMINER
ACKNOWLEDGEMENT
I am overwhelmed in all humbleness and gratefulness to acknowledge my depth
to all those who have helped me to put these ideas, well above the level of
simplicity and into something concrete.
I would like to express my heartfelt gratitude to my parents who helped me a lot
in gathering different information opportunity to do this wonderful project,
which also helped me in doing a lot of Research and I came to know about so
many new things. I am really thankful to them., collecting data and guiding me
from time to time in making this project, despite of their busy schedules, they
gave me different ideas in making this project unique.
I would like to express my deepest gratitude to my brother for helping me in
every step of the way while putting together my project.
I would like to express my special thanks of gratitude to my teacher as well as
our principal who gave me the golden opportunity to make this happen.
I would like to express my deep gratitude towards the almighty god for leading
me to this project and giving strength for its completion.
Without them I wouldn’t be able to complete this project.
Thank you.
INDEX

S. No. Contents Page No.

1 Introduction to 1
python

2 Program analysis 2

3 Source code 3

4 Sample output 10

5 Reference 21
INTRODUCTION TO PYTHON
Python is an easy to use, interpreted, high-level programming language. It is an
expressive language that has so many convenient features which makes it highly
user friendly. Python’s simple syntax and high readability reduces cost for
program maintenance and makes it really efficient. Often, programmers fall in
love with Python because of the increased productivity it provides and a lot of
useful and fun applications and software can be made with it. Including this fun
little game ‘HANGMAN’.
Although it is not perfect, yet it has a lot of pluses and strengths which helped
me in a lot of ways to complete this project in time. Firstly, it is an interpreted
language which means there is no compilation step and the edit-test-debug cycle
is incredibly fast. I could repeatedly test the program and make the necessary
changes then and there itself without the need to complete the code. Speaking of
completing the program, I could not take the computer along with me wherever
I go. But python’s portability made it even easier to use. It’s a multi-platform
language so, I would type the code using other devices whenever its convenient.
Especially I used my smartphone to design the ASCII character for hangman.
For completing this program, I had to use few modules for specific functions.
There was no need to download those additional libraries because you get
everything while installing python. Its completeness is surely an advantage.
PROGRAM ANALYSIS
AIM:
To create “Hangman” game which is fun and knowledgeable using the concepts
learnt.

OBJECTIVE:
A number of dashes representing the word to be guessed along with its
corresponding clue will be displayed.
Using the clue and dashes which gets filled while playing with correct letters,
the player has to guess the word correctly.
The player cannot make more than 6 mistakes or the man will be hanged.

LOGIC USED:
Module used: Random module
While loop is used to iterate the program as long as the player has not made
more than 6 mistakes or not guessed the correct word yet.
For each iteration, the player is asked to guess a letter with the given clue.
Using if – else condition statements, if the guessed letter is correct, then an
appropriate message is displayed.
If not, when the guessed letter is incorrect, the number of lives decreases by one
and an alerting message is displayed. Also, the hangman character develops by
one step till the player makes 6 mistakes in total and loses the game.
In both cases, for each iteration, the player’s progress in guessing the word (i.e.,
mix of dashes and guessed words) along with number of lives left is displayed.
Once the game ends, the program asks the player for the choice of playing again
or not and the loop repeats or terminates respectively.
SOURCE CODE
#COMPUTER SCIENCE PROJECT
#HANGMAN

#initialize
play_again = ["y", "Y", "yes", "YES", "yeah", "Yeah"]

#loop for playing again


while play_again not in ["n", "N", "no", "No", "NO", "nah", "Nah"]:

#imports
import random

#constants(ASCII hangman)
HANGMAN = ['''
========
[]
[]
[]
[]
[]---------/|
[] / |
---------+ /
---------+/''', '''
========
[] |
[] 0
[]
[]
[]---------/|
[] / |
---------+ /
---------+/''', '''
========
[] |
[] 0
[] |
[] |
[]---------/|
[] / |
---------+ /
---------+/''', '''
========
[] |
[] 0
[] /|
[] |
[]---------/|
[] / |
---------+ /
---------+/''', '''
========
[] |
[] 0
[] /|\\
[] |
[]---------/|
[] / |
---------+ /
---------+/''', '''

========
[] |
[] 0
[] /|\\
[] |
[]----/ ---/|
[] / |
---------+ /
---------+/''','''

========
[] |
[] 0
[] /|\\
[] |
[]----/ \\---/|
[] / |
---------+ /
---------+/''']

wordbank = ["BEAR", "PIZZA", "SNAKE", "WASHINGTON", "MOON",


"YTTERBIUM", "WHAT", "TURKEY", "WATERMELON", "CANDLE", "BARBER",
"MERCURY", "FOOTSTEPS", "PLATE", "FEATHER"]

max_lives = len(HANGMAN)-1
#picking a word
word = random.choice(wordbank)

current_guess = "_ " * len(word)

#wrong guess counter


wrong_guesses = 0

#used letters tracker


used_letters = []

#MAIN LOOP
print('''
.__. .__. ___ .__ __. ______ .___ ___. ___ .__ __.
| | | | / \ | \ | | / ____| | \/ | / \ | \ | |
| |__| | / ^ \ | \| | | | __ | \ / | / ^ \ | \| |
| __ | / /_\ \ | . | | | |_ | | |\/| | / /_\ \ | . |
| | | | / _____ \ | |\ | | |__| | | | | | / _____ \ | |\ |
|__| |__| /__/ \__\ |__| \__| \______| |__| |__| /__/ \__\ |__| \__|
''')

print("""
Welcome to HANGMAN!!!

You are going to be hanged...


But you can escape!
To escape, try to guess the word
You have 6 tries""")

#Printing clue for respective word


if word == 'BEAR':
print('''
CLUE: One of the most intelligent animals in
north America, weighs over 1000 pounds and can run up to 40 mph.''')
elif word == 'PIZZA' :
print('''
CLUE: Dish of Italian origin consisting of round, flat base of dough
topped with cheese and sauce.''')
elif word == 'SNAKE':
print("""
CLUE: They're venomous, they shed their skin, they hisssss.....""")
elif word == 'WASHINGTON':
print("""
CLUE: Only state named after a President""")
elif word == 'MOON':
print("""
CLUE: Only spherical satellite orbiting a terrestrial planet""")
elif word == "YTTERBIUM":
print("""
CLUE: An element named after a town Ytterby, in Sweden.""")
elif word == "WHAT":
print("""
CLUE: What is the answer.""")
elif word == "TURKEY":
print("""
CLUE: One word but represents a bird and a country.""")
elif word == "WATERMELON":
print("""
CLUE: You continue if its red, but stop when its green. What am
I??""")
elif word == "CANDLE":
print("""
CLUE: I'm tall when young, short when old. What am I??""")
elif word == "BARBER":
print("""
CLUE: I shave everyday but my beard stays the same. Who am I??""")
elif word == "MERCURY":
print("""
CLUE: I'm a GOD, I'm a PLANET, I'm used to measure HEAT. What am
I??""")
elif word == "FOOTSTEPS":
print("""
CLUE: The more you take me, the more you leave behind. What am
I??""")
elif word == "FEATHER":
print("""
CLUE: I'm easy to lift but very hard to throw. What am I???""")
elif word == "PLATE":
print("""
CLUE: You buy me to eat but don't eat me. What am I??""")

while wrong_guesses < max_lives and current_guess != word:


print(HANGMAN[wrong_guesses])
print("You have used the following letters:",used_letters)
print("so far, the word is:", current_guess)
print('')

guess = input('Enter your letter guess: ').upper()

#check if letter was already used


while guess in used_letters:
print("You have already guessed the letter", guess,".
SILLY....")
print('')
guess = input("Enter your letter guess:").upper()

#add new guessed letter to list of guesssed letterrs


used_letters.append(guess)

#checking guess(correct guess)


if guess in word:
print("You have guessed correctly! PHEW!!!")

#updating the word with mixed letters and dashes


done = False
new_current_guess = ""
while not done:
for letter in word:
if letter.upper() in used_letters:
new_current_guess += letter
else:
new_current_guess += '_ '
print("")
done = True
current_guess = new_current_guess

#checking guess(wrong guess)


else:
print('')
print("XXX Sorry that was incorrect XXX")
print('')
print('You have', 5 - (wrong_guesses), 'tries left.')
print('')

#increasing no.of incorrect words by 1


wrong_guesses += 1

#End of the game


if wrong_guesses == max_lives:
print("""
========
[] |
[] 0
[] /|\\
[] |
[]----/ \\--/|
[] / |
---------+ /
---------+/""")
print('YOU LOST.')
print("YOU HAVE BEEN HANGED.")
print("The correct word was", word)

if current_guess == word:
print('YOU WON')
print('YES!!! the correct word was', word)
print('YOU BROKE FREE!!!!')

#asking whether to play again or not


print('')
play_again = input('Would you like to play again ?!?!? ')

#by 11205 G J Chandana


#01-02-2025
SAMPLE OUTPUTS
Not proceeding to play again:
Guessing all the letters correctly(winning):
.__. .__. ___ .__ __. ______ .___ ___. ___ .__ __.
| | | | / \ | \ | | / ____| | \/ | / \ | \ | |
| |__| | / ^ \ | \| | | | __ | \ / | / ^ \ | \| |
| __ | / /_\ \ | . | | | |_ | | |\/| | / /_\ \ | . |
| | | | / _____ \ | |\ | | |__| | | | | | / _____ \ | |\ |
|__| |__| /__/ \__\ |__| \__| \______| |__| |__| /__/ \__\ |__| \__|

Welcome to HANGMAN!!!

You are going to be hanged...


But you can escape!
To escape, try to guess the word
You have 6 tries

CLUE: I'm a GOD, I'm a PLANET, I'm used to measure HEAT. What am I??

========
[]
[]
[]
[]
[]---------/|
[] / |
---------+ /
---------+/
You have used the following letters: []
so far, the word is: _ _ _ _ _ _ _

Enter your letter guess: e


You have guessed correctly! PHEW!!!

========
[]
[]
[]
[]
[]---------/|
[] / |
---------+ /
---------+/
You have used the following letters: ['E']
so far, the word is: _ E_ _ _ _ _

Enter your letter guess: r


You have guessed correctly! PHEW!!!

========
[]
[]
[]
[]
[]---------/|
[] / |
---------+ /
---------+/
You have used the following letters: ['E', 'R']
so far, the word is: _ ER_ _ R_

Enter your letter guess: y


You have guessed correctly! PHEW!!!

========
[]
[]
[]
[]
[]---------/|
[] / |
---------+ /
---------+/
You have used the following letters: ['E', 'R', 'Y']
so far, the word is: _ ER_ _ RY

Enter your letter guess: m


You have guessed correctly! PHEW!!!

========
[]
[]
[]
[]
[]---------/|
[] / |
---------+ /
---------+/
You have used the following letters: ['E', 'R', 'Y', 'M']
so far, the word is: MER_ _ RY

Enter your letter guess: u


You have guessed correctly! PHEW!!!

========
[]
[]
[]
[]
[]---------/|
[] / |
---------+ /
---------+/
You have used the following letters: ['E', 'R', 'Y', 'M', 'U']
so far, the word is: MER_ URY

Enter your letter guess: c


You have guessed correctly! PHEW!!!

YOU WON
YES!!! the correct word was MERCURY
YOU BROKE FREE!!!!
Would you like to play again ?!?!? no
Guessing the letters incorrectly(losing):
.__. .__. ___ .__ __. ______ .___ ___. ___ .__ __.
| | | | / \ | \ | | / ____| | \/ | / \ | \ | |
| |__| | / ^ \ | \| | | | __ | \ / | / ^ \ | \| |
| __ | / /_\ \ | . | | | |_ | | |\/| | / /_\ \ | . |
| | | | / _____ \ | |\ | | |__| | | | | | / _____ \ | |\ |
|__| |__| /__/ \__\ |__| \__| \______| |__| |__| /__/ \__\ |__| \__|

Welcome to HANGMAN!!!

You are going to be hanged...


But you can escape!
To escape, try to guess the word
You have 6 tries

CLUE: Only state named after a President

========
[]
[]
[]
[]
[]---------/|
[] / |
---------+ /
---------+/
You have used the following letters: []
so far, the word is: _ _ _ _ _ _ _ _ _ _

Enter your letter guess: j

XXX Sorry that was incorrect XXX

You have 5 tries left.

========
[] |
[] 0
[]
[]
[]---------/|
[] / |
---------+ /
---------+/
You have used the following letters: ['J']
so far, the word is: _ _ _ _ _ _ _ _ _ _

Enter your letter guess: e

XXX Sorry that was incorrect XXX

You have 4 tries left.

========
[] |
[] 0
[] |
[] |
[]---------/|
[] / |
---------+ /
---------+/
You have used the following letters: ['J', 'E']
so far, the word is: _ _ _ _ _ _ _ _ _ _

Enter your letter guess: q

XXX Sorry that was incorrect XXX

You have 3 tries left.

========
[] |
[] 0
[] /|
[] |
[]---------/|
[] / |
---------+ /
---------+/
You have used the following letters: ['J', 'E', 'Q']
so far, the word is: _ _ _ _ _ _ _ _ _ _

Enter your letter guess: y

XXX Sorry that was incorrect XXX

You have 2 tries left.

========
[] |
[] 0
[] /|\
[] |
[]---------/|
[] / |
---------+ /
---------+/
You have used the following letters: ['J', 'E', 'Q', 'Y']
so far, the word is: _ _ _ _ _ _ _ _ _ _

Enter your letter guess: n


You have guessed correctly! PHEW!!!

========
[] |
[] 0
[] /|\
[] |
[]---------/|
[] / |
---------+ /
---------+/
You have used the following letters: ['J', 'E', 'Q', 'Y', 'N']
so far, the word is: _ _ _ _ _ N_ _ _ N
Enter your letter guess: p

XXX Sorry that was incorrect XXX

You have 1 tries left.

========
[] |
[] 0
[] /|\
[] |
[]----/ ---/|
[] / |
---------+ /
---------+/
You have used the following letters: ['J', 'E', 'Q', 'Y', 'N', 'P']
so far, the word is: _ _ _ _ _ N_ _ _ N

Enter your letter guess: z

XXX Sorry that was incorrect XXX

You have 0 tries left.

========
[] |
[] 0
[] /|\
[] |
[]----/ \--/|
[] / |
---------+ /
---------+/
YOU LOST.
YOU HAVE BEEN HANGED.
The correct word was WASHINGTON
Would you like to play again ?!?!? no
Proceeding to play again:
.__. .__. ___ .__ __. ______ .___ ___. ___ .__ __.
| | | | / \ | \ | | / ____| | \/ | / \ | \ | |
| |__| | / ^ \ | \| | | | __ | \ / | / ^ \ | \| |
| __ | / /_\ \ | . | | | |_ | | |\/| | / /_\ \ | . |
| | | | / _____ \ | |\ | | |__| | | | | | / _____ \ | |\ |
|__| |__| /__/ \__\ |__| \__| \______| |__| |__| /__/ \__\ |__| \__|

Welcome to HANGMAN!!!

You are going to be hanged...


But you can escape!
To escape, try to guess the word
You have 6 tries

CLUE: Only spherical satellite orbiting a terrestrial planet

========
[]
[]
[]
[]
[]---------/|
[] / |
---------+ /
---------+/
You have used the following letters: []
so far, the word is: _ _ _ _

Enter your letter guess: n


You have guessed correctly! PHEW!!!

========
[]
[]
[]
[]
[]---------/|
[] / |
---------+ /
---------+/
You have used the following letters: ['N']
so far, the word is: _ _ _ N

Enter your letter guess: a

XXX Sorry that was incorrect XXX

You have 5 tries left.

========
[] |
[] 0
[]
[]
[]---------/|
[] / |
---------+ /
---------+/
You have used the following letters: ['N', 'A']
so far, the word is: _ _ _ N

Enter your letter guess: m


You have guessed correctly! PHEW!!!

========
[] |
[] 0
[]
[]
[]---------/|
[] / |
---------+ /
---------+/
You have used the following letters: ['N', 'A', 'M']
so far, the word is: M_ _ N

Enter your letter guess: o


You have guessed correctly! PHEW!!!

YOU WON
YES!!! the correct word was MOON
YOU BROKE FREE!!!!

Would you like to play again ?!?!? yes

.__. .__. ___ .__ __. ______ .___ ___. ___ .__ __.
| | | | / \ | \ | | / ____| | \/ | / \ | \ | |
| |__| | / ^ \ | \| | | | __ | \ / | / ^ \ | \| |
| __ | / /_\ \ | . | | | |_ | | |\/| | / /_\ \ | . |
| | | | / _____ \ | |\ | | |__| | | | | | / _____ \ | |\ |
|__| |__| /__/ \__\ |__| \__| \______| |__| |__| /__/ \__\ |__| \__|

Welcome to HANGMAN!!!

You are going to be hanged...


But you can escape!
To escape, try to guess the word
You have 6 tries

Continues….
FUTURE SCOPES OF THIS PROJECT:
1. Enhancing User Experience :
Implementing graphical improvements with animations and sound effects.
Introducing hints and power-ups to make the game more interactive.
2. Expanding Game Modes
Multiplayer Mode: Allowing two or more players to compete online.
Challenge Mode: Timed levels where players must guess words within a set
time.
Adaptive Difficulty: The game adjusts based on the player’s performance.
3. Educational Applications
Using Hangman for language learning and vocabulary building.
Developing subject-specific versions (e.g., medical terms, coding concepts).
4.Virtual Reality (VR) & Augmented Reality (AR) :
Creating an immersive VR Hangman experience.
Using AR to visualize words and guesses in real-world environments.
5. Security & Fair Play Enhancements
Preventing cheating in online multiplayer using anti-cheat algorithms.
Blockchain-based secure word packs and authentication.

RESULT:
The game was launched and run successfully.
REFERENCE:
 Class 11 textbook - “Progress in COMPUTER SCIENCE and getting
ahead with PYTHON” by Sumita Arora.
 MJ codes – YouTube: https://youtu.be/wmSysRui0cI
 NeuralNine – YouTube: https://youtu.be/5x6iAKdJB6U

You might also like