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

Hangman Game Documentation - With Code

The document describes a Hangman game project created using Python. Key aspects include: - The program randomly selects a word from lists in 3 categories (animals, vegetables, sports) for the user to guess. - Users have 8 lives and lose a life for each incorrect letter guess. They win by guessing the full word. - The code uses concepts like lists, length, boolean, indexing, and random selection to run the game. - Testing showed the program successfully runs the game and displays the secret word when won or lost.

Uploaded by

Dania Noman
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
417 views

Hangman Game Documentation - With Code

The document describes a Hangman game project created using Python. Key aspects include: - The program randomly selects a word from lists in 3 categories (animals, vegetables, sports) for the user to guess. - Users have 8 lives and lose a life for each incorrect letter guess. They win by guessing the full word. - The code uses concepts like lists, length, boolean, indexing, and random selection to run the game. - Testing showed the program successfully runs the game and displays the secret word when won or lost.

Uploaded by

Dania Noman
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

1

WINTER CAMP - INTERNSHIP - TASK

INFORMATION TECHNOLOGY - PYTHON


CURTIN UNIVERSITY, DUBAI

HANGMAN PROJECT

Name:
Dania Noman Ali
2

Acknowledgements
I would like to express my gratitude and thanks to Ms. Shahra Jafar
and the faculty at Curtin University, Dubai for their guidance and
unparalleled support throughout the process of making my Hangman
Project.

Furthermore, I would like to thank my family for giving me the


motivation
and support, along with the necessary resources to build the project
and execute it.
3

INDEX

S.NO TOPICS PAGE


1 Abstract 4
2 Background 4
3 Methodology 4
4 Program Code 5
5 Results 6
6 Conclusion 9
7 Future Work 10
4

Abstract
The topic I chose aims at creating a program which relies on a “Guess
the Word” Approach. With the help of valuable concepts such as lists,
obtaining the length of a word, boolean, index, built in graphics and
mainly the ‘Random Function’, this program can be used to play the
game of hangman.
My main idea was to come up with a program that was both easy and
captivating to play in the realm of a word-guessing game, Hangman.
I paid special heed to categorizing the lists of the words into 3 types
for user-diversity and interest.

Background
The topic I chose aims at creating a program which relies on a “Guess
the Word” Approach. In an original Hang-man play, you are shown a
blank set of spaces which are supposedly filled in when the user
makes a random letter guess. With every incorrect guess that the user
makes, a line is drawn in order to make a stickman. As the number of
incorrect guesses increases, so does the stickman and its finally
‘hung’. When that happens, the game is lost. This is the reason to why
the game is called ‘Hangman’.

Methodology
The program makes use of the ‘random’ module to pick out a random
word from the list of predetermined words.

The list of words are divided into 3 categories (animal, vegetables and
sports) so the user may use the one which they are most interested in.
5

The user gets 8 lives. With each following incorrect guess, the number
of lives reduce by -1. If the user guesses the word and finally types in
the full word, they win, with the program displaying a ‘'Winner Winner
Chicken Dinner’ message as well as the correct word alongside it.

Code
import random
animal_words = ('giraffe','cat','lion','tiger','rabbit')
vegetables_words = ('carrot','cucumber''cauliflower','onion','tomato')
sports_words = ('football','cricket','basketball','swimming')
words = input("Choose one of the following categories: animals,
vegetables or sports:")
if words== 'animals':
secret_word = random.choice(animal_words)
elif words == 'vegetables':
secret_word=random.choice(vegetables_words)
elif words == 'sports':
secret_word = random.choice(sports_words)
else:
print('Ops Invalid Choice!')
lives = 8
lengh_secretword= len(secret_word)
hint = list('?'*lengh_secretword)
heart_symbol = u'\u2764'
Word_guessed_correctly = False
def update_hint(guessed_letter, secret_word, hint):
index = 0
while index < len(secret_word):
if guessed_letter==secret_word[index]:
hint[index] = guessed_letter
index = index + 1
print ('\n')
6

print('Here is the hint, the word is', len(secret_word),' characters long')


while lives > 0:
print(hint)
print('Lives left: ' + heart_symbol * lives)
guess = input('Guess a letter or the whole word')
if guess == secret_word:
Word_guessed_correctly = True

if guess in secret_word:
print('That RIGHT!, Glance over the updated hint')
update_hint(guess, secret_word, hint)
else:
print('WRONG. You lost a life. Keep Trying')
lives = lives -1
if Word_guessed_correctly:
print('Winner Winner Chicken Dinner! The secret word was' +
secret_word)

Results
7
8
9

Conclusion
The program successfully executes and runs out, displaying the secret
word at the end. Proper error management may be observed when an
incorrect letter is typed, leading to a loss of 1 life. The choices for the
categories are clearly laid out and an error message is observed when
an incorrect category is chosen.
While building the program I gained insight on executing the ‘Random’
function correctly. Furthermore, I also learnt the importance of blank
spaces that helps to achieve a cleaner view and layout of the whole
program and thus makes it appear user-friendly. This is a simple
program based on the idea of ‘Hangman’ and ‘Word Guessing’ that
can be played by absolutely anyone.
10

Future Work
With the advancement of programming softwares, namely python,
several areas of my coding can be further enhanced for a visually and
performing better program. Sound effects can be added to notify the
winning of the game in the program to make it appealing for the user.
Moreover, visual effects and images can be used in the program to
make it interesting.

You might also like