Hangman Game Documentation - With Code
Hangman Game Documentation - With Code
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.
INDEX
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
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.