Hangman Game in Python | Python Project #3 | Python Project for beginners
ฝัง
- เผยแพร่เมื่อ 30 เม.ย. 2023
- In this Python Lecture we are going to build Hangman Game . We will discuss the Complete Code line-by-line. The game will allow for user input, and will also output a visual of the hangman alongside the word that’s being guessed.
Best Python Tutorials for Beginners: • Python - Basic to Advance
*********************************************
Connect & Contact Me:
My Second Channel Link: bit.ly/354n7C7
Facebook: / jennys-lectures-csit-n...
Quora: www.quora.com/profile/Jayanti...
Instagram: / jayantikhatrilamba
Twitter: / khatrijenny
*******************************************
More Playlists:
Programming in C Tutorials: • Programming in C
C++ Tutorials for beginners: • Lec 1: How to Install ...
Placement Series: • Placements Series
Data Structures and Algorithms: https: • Data Structures and Al...
Design and Analysis of Algorithms(DAA): • Design and Analysis of...
Dynamic Programming: • Dynamic Programming
Operating Systems tutorials: // • Operating Systems
DBMS Tutorials: • DBMS (Database Managem...
#pythonprojects #pythonforbeginners #python #jennyslectures #pythonprogramming #hangman
I just like how you break complex problems into small problems in order to have them solved,, the way you pause and think and write code is very helpful for someone who wants to really learn how to solve programming problems not only in python but any language for that matter! Thank you Jenny!
Well this was really crazy in a good way, i don't know if this channel is for explaining kids but i am 24years old & enjoying it
Mam pls start machine learning Playlist, i beg u 😭😭🙏🏻🙏🏻🙏🏻
I'm also waiting for that
Yes mam
Yes
I think she has already done a superb job teaching python, I would probably master python well first if I were you
@@lifebyvikk6751 i have already mastered python bro, now i want to learn ML
Mam please tell how to draw this Hangman pictures
just subscribed
and started watching
waah didi waaah..waah didi waah...what an explanation?
IT DOESNT WORK WHEN U DO THE HANGMAN STGES IT IS SHOWING OUT OF INDEX WHEN I RUN IT PLS HELP
In the program of hangman game you have not defined lives. Your program is not showing name error for lives but mine is showing name error. please clear it mam
How to u code the figure? The hangman stages that u just imported
Mam this has one problem that is if we enter correct letter again in the input it will not take lives it's like we can run this continuously until the whole list of "_" these characters is replaced with letters
Mam can you make a playlist on asymptotic notation pls😃😃😃
Like u said we can make this hangman game in multiple ways can u please elaborate so that we can understand
Hangman module not found error mam
8:48 match expressions😊
Thank You So Much
type error = showing cannot concatenate list (not "str") to list ,
in line display = display + '_' ,
mam can u explain this problem
THANK YOU SO MUCH MAAM
Thank you so much mam😊😊😊😊
Very good 🎉😂
mam what if a user enter's a correct word repeatedly??
Mam Do one video on Java Programming Basics
hello mam,i have a doubt..suppose one word has two or three same letters like example swiss.if we guess a lettter s from word it should placed only one s.. right ?but in our program at a time three 3 S are placed in display..only one letter should be placed by one chance.please clarify my doubt mam
Hello ma'am,
Can you please make a video on python import time?
I would really appreciate it.
Thank you!
Ma'am I'm currently studying in 1st year of diploma in computer science and technology and my dream is to give gate exam and python is my favorite language and I don't want to do any job , I want to be a data scientist professional and want to research about data science field like machine learning, deep learning, artificial intelligence, etc..
I have a question
what is big data?
and I want to say you to make this course as a professional python developer
But how you make hangman_stages?
Mam can you please send me the details how to make a website
I want to make a website
Mam ,provide notes in description please 😊😊
Please provide code in the description
Maam I am just pass class 12th with( PCM) but ab Samajh nhi aa rha Iska kya 🤔kru?
Mam instead of making an empty list can we write
for i in chosen_list:
print("_", end=" ")
Will we get blanks mam??
display = ['_']*len(chosen_word) #This will do your job
Hello mam
mam please make video on numpy, matplotlib, and pandas library of python because i am preparing as a data analytics and these library is necessary for being data analytics ur concept and way of teaching is very elegant and fabulous i learn data structures from your tutorial and suggest my junior to watch your video of DSA please mam make video on these library tl
thank you
Mam its a humble request please start c++, I have c++ in my 3 rd sem and currently i am in 2nd sem , so i will need it in 3rd sem .
Mam where should i run this code
In jupyter notebook or vs code
Vs is better
No module named hangman_stages
Mam could u plz start java
Mam please Start Java Classes
Plzz mam start the classes of data science alsoo
mam please teach us java too
In Python 3.12, it is showing the hangman_stages function is not compatible.
Please let me know if there is any other function which can be used in 3.12
it is not an inbuild function it is another python file she created naming "hangman_stages"
#need machine learning playlist
Hi Madam,
I have doubt in this session, How did you add display variable(list data type) with '_' string. Because those are different data type. Can you provide the answer for this doubt.
The list contains an empty string, we are just concatenation with another string.
Ma'am I am currently in 1st year of btech and I want to prepare for gate. When do you think I should start preparing for it please tell me 🙏
for the 1st 2-3 years focus on learning and building projects and also do internship in the 3rd year and based on that decide if you have to or want to do gate or not. if you decide you have better opportunities already because you have built good projects and have proof of work then leave it else if you still want to pursue gate then start. 1 and half year of dedicated preparation is good enough for gate.
💞👍👍👍
Ma'am you better start your own college,,,,,,i am from non cs branch,,,,,you will get me and my friends as students for sure 🥺
I'm also
Mam please start Java play list
mam quality to improve karo, like camera or iphone, or may be the compression is bit high
What is meant by "Scratch file" which is displayed at top left corner of "Pycharm" application under pythonProject~New~Scratch File. Please 🥺 mam!
Scratch file is just like any other file types like python file or html file or text file. Scratch is the most basic programming language one can learn, usually taught to kids in school. Pycharm has Scratch file as it's default file like how notepad has text file as default, u can change it to python by saving it with .py extension or as text file with .txt extension
Mam uploaded more and more python videos please
Mam please complete c++ videos
hello im rhey from philippines
Mam we want emcet online classes
import random
print("WELCOME TO HANGMAN")
heart=6
won=False
list1= ["lamp", "chair", "book", "spoon", "tree", "hat", "bike", "door", "pen", "cup", "shoe", "clock", "ball", "table", "sun", "moon", "flower", "bridge", "cloud", "pillow"]
# random words
word=random.choice(list1)#choose a random word from the list
word=list(word)#make it in to list again
output = ["_"] * len(word)
print(output)
while heart:
guess=input("Guess a letter")
for i in range(len(word)):
if(guess==word[i]):
output[i]=guess
print(output)
if(output==word):
won=True
print("you won!")
if (guess not in word):
heart -= 1
print(f"You have {heart} heart left")
if(won==True):
break
if(heart==0):
print(f"The word is {word}")
Excellent..💫
guess=input("Guess a letter").lower()
Super bro..... ❤❤
thanks mam if you can please send us your source code Thank you
Madam iff possible pl use hindi or mixed lang
Third👍
Mam vs code me karo code ko .......
I love you 😍 💗 mam
Madam please make sure send notes in description madam please it's my humble request 😢😢😢
here for beauty
First
Third😄😄😄😂
Mam u r so very beautiful
🥵🥵🥵
Second
come to pakistan.
Zero
Hlo mam
Mam 😢
Here's what each part of the code does:
1. **Imports and Initial Setup**
import random
import hangman_stages
import words_file
```
These lines import the necessary modules for the game. `random` is a built-in Python module for generating random numbers. `hangman_stages` and `words_file` are custom modules that contain the hangman stages and the word list, respectively.
2. **Game Variables**
lives=6
chosen_word=random.choice(words_file.words)
print(chosen_word)
```
Here, the variable `lives` is set to 6, representing the number of incorrect guesses the player is allowed. `chosen_word` is a randomly selected word from the word list in `words_file`. This word is what the player has to guess.
3. **Display Setup**
display=[]
for i in range(len(chosen_word)): #0 1 2 3 4
display +='_'
print(display)
```
This code creates a list `display` that is used to show the player's progress in guessing the word. It starts as a list of underscores, with one underscore for each letter in `chosen_word`.
4. **Game Loop**
while not game_over:
letter_guess = input('Guess the letter ').lower() # r
for position in range(len(chosen_word)):
letter=chosen_word[position]
if letter==letter_guess:
display[position] = letter_guess
print(display)
```
This is the main game loop. The player is asked to guess a letter, which is then checked against each letter in `chosen_word`. If the guessed letter is in the word, the corresponding underscore in `display` is replaced with the letter.
5. **Lives and Game Over Conditions**
if letter_guess not in chosen_word:
lives -= 1
if lives == 0:
game_over = True
print('Game Over, You Lose! ')
if '_' not in display:
game_over = True
print('You win!! ')
print(hangman_stages.stages[lives])
```
If the guessed letter is not in the word, the player loses a life. If all lives are lost (`lives == 0`), the game ends and the player loses. If there are no more underscores in `display`, meaning the player has guessed all the letters, the game also ends and the player wins. After each guess, the current hangman stage is printed based on the number of remaining lives.
Mam I am a student of MITS Gwalior please help me python language
Python language is non living thing bruh, how it can help u 😢😢😭😭
@@Arceus948😂😂😂😂
Mam will you marry me 😊😊
# without figure and alternatives which are commented
import random
list_1 = ["apple", "banana", "cherry", "avocado", "kiwi", "jackfruit"]
task_1 = random.choice(list_1)
# list_2 = []
print("Guess name of the fruit ! ")
#for dash in task_1:
#list_2.append("_")
# list_2 += "_"
hidden_word = ["_"] * len(task_1)
# print(hidden_word) is a list of strings
print("".join(hidden_word)) # strings joined
# print(hidden_word) remains a list of strings
attempts = 0
no_of_guesses = 6
guessed_letter = set()
while "_" in hidden_word and attempts < no_of_guesses:
guess = input("Guess a letter of the word: ")
if len(guess) != 1:
print("Enter a single letter at a time! ")
elif guess in guessed_letter:
print("Already guessed, life reduced !")
attempts += 1
print(f"{no_of_guesses - attempts} lives remaining")
else:
guessed_letter.add(guess)
if guess in task_1:
for i in range(len(task_1)):
# for i, letter in enumerate(task_1):
if task_1[i] == guess:
# if letter == guess and hidden_word[i] == "_":
hidden_word[i] = guess
# print(hidden_word)
print("".join(hidden_word))
else:
attempts += 1
print(f"You have {no_of_guesses - attempts} guess left.")
if "_" not in hidden_word:
print("Congratulation, you have guessed the word")
else:
print(f"Your chances are over, the correct word is {task_1}")
import random
fruits = ["apple", "banana", "orange", "grape", "kiwi", "strawberry", "watermelon", "pineapple", "blueberry", "mango", "pear", "peach", "plum", "cherry", "raspberry", "blackberry", "lemon", "lime", "coconut", "pomegranate", "apricot", "fig", "nectarine", "cranberry", "grapefruit", "tangerine", "lychee", "dragonfruit", "guava", "passionfruit", "melon", "persimmon", "kiwifruit", "cantaloupe", "honeydew", "date", "papaya", "jackfruit", "elderberry", "starfruit", "rhubarb", "boysenberry", "carambola", "kumquat", "soursop", "ackee", "breadfruit", "durian", "longan", "tamarind", "mulberry", "plantain", "quince", "soursop", "uglifruit"]
guess=random.choice(fruits)
length=len(guess)
list1=[]
for i in range(length):
list1.append("-")
print(list1)
flag=0
n=0
while('-' in list1 and n!=6):
x=input("guess the alphabet ")
for i in range(length):
if guess[i]==x:
flag=1
list1[i]=x
if(flag==1):
print(list1)
print("correct")
if(flag==0):
n+=1
print(list1)
print("incorrect")
print(f"you lose {n} life")
flag=0
if '-' in list1:
print(f"the correct answer was {guess}")
print("
you lose the game")
else:
print("
you win the game")