Hi I need to make a hangman game for school task and it is no an ordinary game. It has to incorporate the pictures and everytime something wrong is guessed it has to clock over the pictures. The pictures are:
hangman_pics = ['''
+---+
| |
|
|
|
|
=========''',
'''
+---+
| |
O |
|
|
|
=========''',
'''
+---+
| |
O |
| |
|
|
=========''',
'''
+---+
| |
O |
/| |
|
|
=========''',
'''
+---+
| |
O |
/|\ |
|
|
=========''',
'''
+---+
| |
O |
/|\ |
/ |
|
=========''',
'''
+---+
| |
O |
/|\ |
/ \ |
|
========='''
]
Other than this, the game functions just as normal just like any other one where it has output as that was wrong guess or nice guess and stops after 10 guesses and has a list of words to choose from and always shows the progress of word to the player as well as displaying the incorrectly guessed words.
A.K.A I just want it to follow this hangman game procedure:
import random def hangman(): secret_words = ['I love python',"Hello world","Programming is Fun"] random_index = random.randint(0,len(secret_words)-1) word_to_be_guessed=secret_words[random_index].lower() user_word = [] guess_count=0 print("Current guesses") for c in word_to_be_guessed: if c ==" ": user_word.append(" ") print(" ", end=" ") else: user_word.append("_") print("_",end=" ") while True: if(guess_count==20): break letter= input("\nEnter your next letter to guess: ") guess_count+=1 index=0 for i in range(0,len(word_to_be_guessed)): if(word_to_be_guessed[i]==letter): user_word[i]=letter print("Current guesses") print(" ".join(user_word)) if(word_to_be_guessed=="".join(user_word)): print("You win :-)!! The hangman sentence is: ",word_to_be_guessed,'!') break
THANK YOU!
Thanks for the question. Below is the code you will be needing Let me know if you have any doubts or if you need anything to change. Thank You !! ================================================================================================ import random def draw(i): hangman_pics = [''' +---+ | | | | | | =========''', ''' +---+ | | O | | | | =========''', ''' +---+ | | O | | | | | =========''', ''' +---+ | | O | /| | | | =========''', ''' +---+ | | O | /|\ | | | =========''', ''' +---+ | | O | /|\ | / | | =========''', ''' +---+ | | O | /|\ | / \ | | =========''' ] print(hangman_pics[i]) def hangman(): secret_words = ['I love python',"Hello world","Programming is Fun"] random_index = random.randint(0,len(secret_words)-1) word_to_be_guessed=secret_words[random_index].lower() user_word = [] guess_count=0 print("Current guesses") for c in word_to_be_guessed: if c ==" ": user_word.append(" ") print(" ", end=" ") else: user_word.append("_") print("_",end=" ") index = 0 while True: if(guess_count==20): break letter= input("\nEnter your next letter to guess: ") guess_count+=1 flag=False for i in range(0,len(word_to_be_guessed)): if(word_to_be_guessed[i]==letter): user_word[i]=letter flag=True if flag==True: print("Current guesses") print(" ".join(user_word)) else: draw(index) index+=1 if( index==7): print('Game over.') break if(word_to_be_guessed=="".join(user_word)): print("You win :-)!! The hangman sentence is: ",word_to_be_guessed,'!') break hangman()
==========================================================================================
Get Answers For Free
Most questions answered within 1 hours.