Professional Documents
Culture Documents
Mini Project Hangman Game
Mini Project Hangman Game
HANGMAN GAME
Submitted By:
Certificate
This is to certify that the project entitled “HANGMAN GAME” is a bonafede
work carried out by Lakshay Mullick (20016101100116) and Jatin Gupta
(2001610100102) as a part of “ Mini Project” Computer Science and Engineering
during the year 2 0 2 2 -
2023.
This is a simple Hangman game using Python programming language. We can use this as
a small project to boost their programming skills and understanding logic. The Hangman
program randomly selects a secret word from a list of secret words. The random module will
provide this ability, so line 1 in program imports it. Hangman is a popular word game in
which one player (the "chooser") chooses a secret word and another player (the "guesser")
attempts to guess the word one letter at a time. If a guessed letter appears in the word,
all instances of it are revealed. If not, the guesser loses a chance. If the guesser figures
out the secret word before
he or she runs out of chances, he or she wins. If not, the player who chose the word wins.
TABLE OF CONTENTS
TOPIC PAGE NO
1. INTRODUCTION
2. SYSTEM REQUIREMENTS
3.2. Results 10
CONCLUSION 12
REFERENCES 12
Hangman Game
Chapter 1: Introduction
This chapter includes brief introduction to Python Programming Language and its applications.
Conclusion
This section includes the conclusion about the project.
References
This section includes the bibliographical references used for the development of the project.
CHAPTER 1
INTRODUCTION
1.1. Python Programming language
Python is one of the many open source object oriented programming application
software available in the market . Python is developed by Guido van Rossum. Guido
van Rossum started implementing Python in 1989. Python is a very simple programming
language so even if you are new to programming, you can learn python without facing any
issues. Some of the many uses of Python are application development, implementation
of automation testing process, allows multiple programming build, fully constructed
programming library, can be used in all the major operating systems and platforms,
database system accessibility, simple and readable code, easy to apply on complex
software development processes, aids in test driven software application development
approach, machine learning/ data analytics, helps pattern recognitions, supported in
multiple tools, permitted by many of the provisioned
frameworks, etc.
Some features of Python are-
2. Easy to Learn: Learning python is easy as this is a expressive and high level
programming language, which means it is easy to understand the language and thus easy to learn.
3. Cross platform: Python is available and can run on various operating systems such as
Mac, Windows, Linux, Unix etc. This makes it a cross platform and portable language.
5. Large standard library: Python comes with a large standard library that has some handy
codes and functions which we can use while writing code in Python.
6. Free: Python is free to download and use. This means you can download it for free and use it
in your application. See: Open Source Python License. Python is an example of a FLOSS
(Free/Libre Open Source Software), which means you can freely distribute copies of this software,
read its source
7. Supports exception handling: If you are new, you may wonder what is an exception? An
exception is an event that can occur during program exception and can disrupt the normal flow
of program. Python supports exception handling which means we can write less error prone code and
can test various scenarios that can cause an exception later on.
8. Advanced features: Supports generators and list comprehensions. We will cover these
features later.
Python can be used to develop different applications like web applications, graphic user
interface based applications, software development application, scientific and numeric
applications, network programming, Games and 3D applications and other business applications.
It makes an interactive interface and easy development of applications. You may be wondering
what all are the applications
ofPython. There are so many applications of Python, here are some of the them.
1. Web development – Web framework like Django and Flask are based on Python. They help
you write server side code which helps you manage database, write backend programming logic,
mapping urls etc.
2. Machine learning – There are many machine learning applications written in Python.
Machine learning is a way to write a logic so that a machine can learn and solve a particular
problem on its own. For example, products recommendation in websites like Amazon, Flipkart,
eBay etc. is a machine learning algorithm that recognises user’s interest. Face recognition and
Voice recognition in your phone is another example of machine learning.
3. Data Analysis – Data analysis and data visualisation in form of charts can also be developed
using Python.
4. Scripting – Scripting is writing small programs to automate simple tasks such as sending
automated response emails etc. Such type of applications can also be written in Python programming
language.
7.Desktop applications – You can develop desktop application in Python using library like TKinter
or QT.
CHAPTER 2
SYSTEM REQUIREMENTS
CHAPTER 3
1. The Hangman program randomly selects a secret word from a list of secret words. The
random module will provide this ability, so line 1 in program imports it.
2. The Game: Here, a random word (a fruit name) is picked up from our collection and the
player gets limited chances to win the game.
3. When a letter in that word is guessed correctly, that letter position in the word is made visible.
In this way, all letters of the word are to be guessed before all the chances are over.
4. For convenience, we have given length of word + 2 chances. For example, word to be guessed
is mango, then user gets 5 + 2 = 7 chances, as mango is a five letter word.
import random
from json import load
def get_word():
with open('words.json') as json_file
data = load(json_file)
wordArray = data["word_list"]
word = random.choice(wordArray)
word = word.upper()
return word
def play(word):
print(display_hangman(tries))
print(word_completion)
print("\n")
print("Length of the word: ", len(word))
print("\n")
if guess in guessed_letters:
print("You already guessed the letter", guess)
tries -= 1
guessed_letters.append(guess)
else:
print("Good job,",guess, "is in the word!")
guessed_letters.append(guess)
word_as_list = list(word_completion)
indices = [i for i, letter in enumerate(word) if letter == guess]
guessed = True
elif len(guess) == len(word) and guess.isalpha():
if guess in guessed_word
print("You already guessed the word", guess)
tries -= 1
guessed_words.append(guess)
else:
guessed = True
word_completion = word
else:
print("Not a valid guess.")
print(display_hangman(tries))
print(word_completion)
print("\n")
if guessed:
print("Congrats, you guessed the word! You win!")
else:
print("Sorry, youran out of tries. The word was " + word + ". Maybe next time!")
def display_hangman(tries):
stages = ["""
--------
| |
| 0
| \\|/
| |
| / \\
-
""",
"""
--------
| |
| 0
| \\|/
| |
""",
"""
| |
0
| \\|/
|
|
|
|
-
""",
"""
| |
0
| \\|
|
|
|
|
-
""",
"""
| |
| 0
| |
-
""",
"""
| |
| 0
|
""",
"""
| |
|
-
"""
]
return stages[tries]
def main():
word = get_word()
play(word)
play(word)
if __name__ == "__main__":
main()
3.3 Results
Snapshots taken from successful runs of the project
CONCLUSION
In the conclusion of this project, Hangman is a traditional game, typically played with words.
It’s possible, however, to play Category Hangman rather than guessing words the player might
guess names of cities, or athletes, or fictional characters, or Duke professors, or top forty song titles
the list is endless. You’ll be writing a program to play a “guess a word letter-by-letter” version of
hangman as
shown above. You’ll also be doing some statistical analysis of the words used in the Hangman game.
REFERENCES
Bibliography:
[1] “Python for everybody”, Charles R.Severance
[2] “Think Python”, Allen B.Downey
[3]”Python programming”, Mark lutz
Websites:
[1]https://www.youtube.com/watch?v=QXeEoD0pB3E&list=PLsyeobzWxl7poL9JTVyndKe6
2ieoN-MZ3
[2]https://www.youtube.com/watch?v=NKVOjPHfiSA
[3] https://www.youtube.com/watch?v=BDi3SD7E6no