Professional Documents
Culture Documents
HANGMAN
HANGMAN
At
Bachelor of Engineering In
By
ARAVIND.K
REG NO : MJ1540
DEPARTMENT OF
MARCH – 2024
COMPUTER SOFTWARE COLLEGE IN
ENGINEERING
BONAFIDE CERTIFICATE
This is to certify that this Project Report is the bonafide work of ARAVIND.K
(Reg. No: MJ1540) who carried out the project entitled “HANGMAN” Tool
using Python Program” under my supervision from Feb 2024 to March 2024.
GUIDANCE
CENTER HEAD
DATE
COMPUTER SOFTWARE
COLLEGE
This project wouldn't have been possible without the collective effort and
collaboration of everyone involved.
Feel free to customize it with the specific names and details relevant to your
project!
INSTITUTION:
TOPIC’S
1. INTRODUCTION
2.1 ADVANTAGES
2.2 APPLICATIONS
3.TKINTER
4.MINI PROJECT
4.1 ABSTRUCT
4.2 ALGORITHM
4.4 OUTPUT
4.5 RULES OF THE GAME
4.8 CONCLUSTION
4.9 REFFERENCES
PYTHON
1.INTRODUCTION
In the late 1980s, history was about to be written. It was that time when
working on Python started. Soon after that, Guido Van Rossum began doing
its application-based work in December of 1989 at Centrum Wiskunde &
Informatica (CWI) which is situated in the Netherlands. It was started as a
hobby project because he was looking for an interesting project to keep him
occupied during Christmas.
The programming language in which Python is said to have succeeded is ABC
Programming Language, which had interfacing with the Amoeba Operating
System and had the feature of exception handling. He had already helped
create ABC earlier in his career and had seen some issues with ABC but liked
most of the features. After that what he did was very clever. He had taken the
syntax of ABC, and some of its good features. It came with a lot of
complaints too, so he fixed those issues completely and created a good
scripting language that had removed all the flaws. The inspiration for the
name came from the BBC’s TV Show – ‘Monty Python’s Flying Circus’, as
he was a big fan of the TV show and also he wanted a short, unique and
slightly mysterious name for his invention and hence he named it Python! He
was the “Benevolent dictator for life” (BDFL) until he stepped down from the
position as the leader on 12th July 2018. For quite some time he used to work
for Google, but currently, he is working at Dropbox
1.2 Applications of Python
a. Web Development:
Python is widely used in web development. It makes use of simple code to build
a beautiful and functional website. It has related libraries and modules like
HTTP, XML, JSON, IMAP, POP, FTP, etc. These help in storage in databases,
content management, and interfacing with internet protocols.
It also has frameworks integrated with it like Django, Flask, Pyramid, and
Bottle. In addition, Python also comes with packages like Beautiful Soup,
Twisted Python, and Feedparser.
c. Game Development:
One of the interesting applications of the Python Programming language is to
build games like egg catcher, snake game, etc.
Python comes with packages like Pygame and Pykyra to build awesome games.
It facilitates the development of 3D games with respective libraries. It is also
used for scripting in many game engines.
Its simplicity and platform independence nature make it a good choice for GUI
applications. Though Tkinter is the standard library for GUI development, there
are other supporting libraries like:
Wx Python
Kivy,PyQt, PySide
e. Enterprise/ Business Applications:
Business applications are developed keeping in mind the comfort and ease of
usage by the organization. Python’s features like scalability, extensibility, and
readability make it the best choice for business applications.
f. Software Development:
Python supports the development of software with its libraries and packages. It
is used for building, testing, management, and so on. For example
g. Educational Purposes:
Python helps beginners get introduced to the Programming environment. It is
because of its simple syntax and beginner-friendly nature. Another reason could
be its scope and reach in the development community.
In this section we will see what are the features of Python programming
language:
Python language is freely available at the official website and you can
download it from the given download link below click on the Download
Python keyword. Download Python Since it is open-source, this means that
source code is also available to the public. So you can download it, use it as
well as share it.
b. Easy to code:
c. Easy to Read:
As you will see, learning Python is quite simple. As was already established,
Python’s syntax is really straightforward. The code block is defined by the
indentations rather than by semicolons or brackets.
d. Object-Oriented Language:
Graphical User interfaces can be made using a module such as PyQt5, PyQt4,
wxPython, or Tk in Python. PyQt5 is the most popular option for creating
graphical apps with Python.
f. High-Level Language:
Python has gained popularity over the years. Our questions are constantly
answered by the enormous Stack Overflow community. These websites have
already provided answers to many questions about Python, so Python users
can consult them as needed.
h. Easy to Debug:
Excellent information for mistake tracing. You will be able to quickly identify
and correct the majority of your program’s issues once you understand how
to interpret Python’s error traces. Simply by glancing at the code, you can
determine what it is designed to perform.
2.1 ADVANTAGES
Open source and large active community base: Python is open source,
and it has a large and active community that contributes to its development
and provides support.
Versatile, easy to read, learn, and write: Python is known for its
simplicity and readability, making it an excellent choice for both
beginners and experienced programmers.
2.2 APPLICATION
Scripting: Python is widely used for writing scripts to automate tasks and
processes.
As this is a site devoted to Python, we’ve already told you why Python is a great
language to learn
3. TKINTER
A form of user interface which allows users to interact with computers through
visual indicators using items such as icons, menus, windows, etc. It has
advantages over the Command Line Interface (CLI) where users interact with
computers by writing commands using keyboard only and whose usage is
more difficult than GUI.
What is Tkinter?
Tkinter is the inbuilt python module that is used to create GUI applications. It
is one of the most commonly used modules for creating GUI applications in
Python as it is simple and easy to work with. You don’t need to worry about
the installation of the Tkinter module separately as it comes with Python
already. It gives an object-oriented interface to the Tk GUI toolkit.
Some other Python Libraries available for creating our own GUI applications
are
Kivy
Python Qt
wxPython
Widgets in Tkinter are the elements of GUI application which provides various
controls (such as Labels, Buttons, ComboBoxes, CheckBoxes, MenuBars,
Radio Buttons and many more) to users to interact with the application.
3.2 FUNDAMENTAL STRUCTURE OF TKINTER PROGRAM
root = Tk()
T.pack()
USES OF TKINTER:
Python offers multiple options for developing GUI (Graphical User Interface).
Out of all the GUI methods, tkinter is the most commonly used method. It is a
standard Python interface to the Tk GUI toolkit shipped with Python. Python
tkinter is the fastest and easiest way to create GUI applications. Creating a
GUI using tkinter is an easy task .
“HANGMAN”
4. MINI PROJECT
4.1 ABSTRUCT:
Initialization:
Selecting a Word:
User Input:
o Compare the guessed letter with the letters in the secret word.
o If the letter is correct, reveal its positions in the word and update
the display.
o If the letter is incorrect, increment the count of incorrect guesses
and possibly update the hangman display.
Game Progression:
End Game:
4.2 ALGORITHM
Eliminate all words in the dictionary that do not have the correct number
of letters.
If this letter does not occur, we know it does not occur in the word.
Eliminate all words in the dictionary subset that do not fit exactly this
correct pattern, and repeat.
If there are 2 (or more) letters appearing equally often, the algorithm may
perform a deeper analysis of the positions to determine which one is
preferred (if that is reasonable?
4.3 SOURCE CODE:
window = Tk()
window.title('Hangman-GUESS GAMES NAME')
word_list=
['CRICKET' ,'HOCKEY' ,'BATMINTON','FOOTBALL' ,'TENNIS' ,'BASKET
BALL']
photos = [PhotoImage(file="images/hang0.png"),
PhotoImage(file="images/hang1.png"), PhotoImage(file="images/hang2.png"),
PhotoImage(file="images/hang3.png"), PhotoImage(file="images/hang4.png"),
PhotoImage(file="images/hang5.png"),
PhotoImage(file="images/hang6.png"), PhotoImage(file="images/hang7.png"),
PhotoImage(file="images/hang8.png"),
PhotoImage(file="images/hang9.png"),
PhotoImage(file="images/hang10.png"),
PhotoImage(file="images/hang11.png")]
def newGame():
global the_word_withSpaces
global numberOfGuesses
numberOfGuesses =0
the_word=random.choice(word_list)
the_word_withSpaces = " ".join(the_word)
lblWord.set(' '.join("_"*len(the_word)))
def guess(letter):
global numberOfGuesses
if numberOfGuesses<11:
txt = list(the_word_withSpaces)
guessed = list(lblWord.get())
if the_word_withSpaces.count(letter)>0:
for c in range(len(txt)):
if txt[c]==letter:
guessed[c]=letter
lblWord.set("".join(guessed))
if lblWord.get()==the_word_withSpaces:
messagebox.showinfo("Hangman","You
guessed it!")
else:
numberOfGuesses += 1
imgLabel.config(image=photos[numberOfGuesses])
if numberOfGuesses==11:
messagebox.showwarning("Hangman","Game
Over")
imgLabel=Label(window)
imgLabel.grid(row=0, column=0, columnspan=3, padx=10, pady=40)
lblWord = StringVar()
Label(window, textvariable =lblWord,font=('consolas 24 bold')).grid(row=0,
column=3 ,columnspan=6,padx=10)
n=0
for c in ascii_uppercase:
Button(window, text=c, command=lambda c=c: guess(c),bg = "blue" , fg =
'white' ,font=('Helvetica 18'), width=4).grid(row=1+n//9,column=n%9)
n+=1
newGame()
window.mainloop()
4.4 OUTPUT:
4.5 RULES OF THE GAME:
There are several ways to enhance the Hangman game to make it more
engaging and enjoyable for players. Here are some ideas for future
enhancements:
Word Database: Expand the word database to include a wider range of words
and phrases, or integrate with online APIs to fetch real-time data for an endless
supply of words.
Custom Word Input: Allow players to input their own words or phrases,
making the game more personalized and interactive.
Sound Effects and Music: Incorporate sound effects and background music to
enhance the atmosphere and immersion of the game.
.
4.7 FLOW CHART:
|
Display Initial Word: The initial display of the word is shown with
underscores for each letter.
Yes: Updates the guessed letters display and checks if the word has been
fully guessed.
No: Increments the number of attempts and checks if the player has run
out of attempts.
Display Updated Word: Shows the updated word with guessed letters
revealed.
All Letters Guessed?: Checks if all letters in the word have been
guessed.
SEQUENCE DIAGRAM:
CLASS DIAGRAM:
4.8 CONCULSION:
Certainly! The conclusion for a Hangman game typically involves informing the
player whether they have won or lost. Here's how the conclusion can be
structured:
Winning Scenario:
If the player successfully guesses all the letters in the word within the allowed
number of attempts, display a congratulatory message.
Optionally, you can display the complete word once again to reinforce their
success.
Losing Scenario:
If the player exhausts all their attempts without correctly guessing the word,
display a message indicating their loss.
Additionally, reveal the complete word to the player so they know the solution.
Example: "Sorry, you ran out of attempts! The word was 'programming'. Better
luck next time!"
Ending Remarks:
Provide a closing message to encourage the player to play again or thank them for
playing.
Example: "Thanks for playing Hangman! Would you like to play again?"
Here's an example of how you can implement the conclusion within the Hangman
game code provided earlier:
This conclusion section ensures that players receive clear feedback on their
performance and are given an opportunity to continue playing or exit the game
gracefully.
4.9 REFFERENCES:
When referencing the implementation of the Hangman game in Python or any
other programming language, you typically don't need specific references unless
you're directly quoting or borrowing code from a particular source. However, if
you're learning about game development, Python programming, or algorithms
related to Hangman, here are some general references you might find helpful:
Python Documentation:
Books:
"Automate the Boring Stuff with Python" by Al Sweigart covers practical Python
programming for beginners and includes chapters on game development.