Day 7 of #100DaysOfCode: Hangman Game
This project has also taken me roughly four to five days as I had other commitments and I faced quite a few problems with the project itself. In this mini project as part of Day 7 of #100DaysOfCode, I have created a Hangman Game using the following python concepts I have learned from Dr Angela Yu's 100DaysOfCode: The Complete Python Bootcamp Udemy course:
For and While Loops
Python Lists
Range
IF/ELSE
Modules
The aim of the Hangman game is the computer selects a random word from a list of words. Then it would prompt the user to guess a letter. If letter is guessed correctly and it matches with the random word, it fills in the blanks for those letters. If an incorrect guess is made, they lose a life. The user starts with 6 lives and if their lives have decreased to zero after a lot of guesses, the game ends. However, if the user has managed to filled in all the blanks with correct guesses to complete the random word, they win.
Python Concepts Used:
For and While Loops
In the Hangman Game, I have used a while loop to define the start and end of the game. This loop continuously evaluates multiple conditions such as if all the blanks have been filled or if the letter has been guessed previously. For each Incorrect guess results in losing a each life in a iteration until it reaches to zero lives. For loops are employed in this game to compare the user's guess with each letter in the random word, sequentially checking for matches. This process continues until the game concludes.
Range
Inside a for loop, range function is used to check if the letter which the user guessed has matched with the letters in the random word. It iterates between between 1 and the length of the word from the random_word
variable.
IF/ELSE Statements
IF/ELSE statements are used to determine whether the letter matches with the letter in the random word. If it does match, the code within the IF statement gets executed. If it doesn't match, the ELSE statement gets executed. It deducts a life for incorrect guesses
Python Lists
Python Lists were used to store words and ASCII art for the game. It also included. The program represents the random word as blanks "_"
, enables to reveal the word as soon as it fills in the blanks.
Modules
In the Hangman Game, the random python module was used to pick a word randomly. Other modules like hangman_words.py
and hangman_art.py
provide variables imported into the main.py
to enhance the games functionality.
Reflections on the Hangman Game
This mini project has been difficult. There were multiple issues that I was facing such as identify how to dynamically fill in the blanks of the letters which the user guessed correctly within the word. Using breakpoints and deeper understanding of while, for and if conditions has massively helped me on overcoming this obstacle. By applying concepts learned from Dr Angela Yu's 100DaysOfCode: The Complete Python Bootcamp Udemy course, I was able to implement multiple functionalities of the Hangman game.
In my opinion, this project has been valuable as it helped reinforce my understanding of the python concepts. Access to full code - https://github.com/keiransystem14/Python100daysofcode/tree/main/Day%207%20Project%20-%20Hangman.