Question

Hi I need to make a hangman game for school task and it is no an...

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!

Homework Answers

Answer #1
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()

==========================================================================================

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
For a C program hangman game: Create the function int setup_game [int setup_game ( Game *g,...
For a C program hangman game: Create the function int setup_game [int setup_game ( Game *g, char wordlist[][MAX_WORD_LENGTH], int numwords)] for a C program hangman game. (The existing code for other functions and the program is below, along with what the function needs to do) What int setup_game needs to do setup_game() does exactly what the name suggests. It sets up a new game of hangman. This means that it picks a random word from the supplied wordlist array and...
use repl.it intro to C-programing no advance code also put good comment that i can know...
use repl.it intro to C-programing no advance code also put good comment that i can know whats this code use for  thank you use repl.it intro to C-programing no advance code also put good comment that i can know whats this code use for  thank you program for a game of hangman. Store the word to be guessed as individual characters of an array called word. The player must guess the letters belonging to word. If the user enters a valid letter,...
Background: In this assignment, you will be implementing Word Guess, a variant of the game Hangman....
Background: In this assignment, you will be implementing Word Guess, a variant of the game Hangman. In this game, a word is first randomly chosen. Initially, the letters in the word are displayed represented by "_”.   For example, if the random word is "yellow”, the game initially displays "_ _ _ _ _ _”. Then, each turn, the player guesses a single letter that has yet to be guessed. If the letter is in the secret word, then the corresponding...
THIS IS FOR JAVA I have to write a method for a game of Hangman. The...
THIS IS FOR JAVA I have to write a method for a game of Hangman. The word the user is trying to guess is made up of hashtags like so " ###### " If the user guesses a letter correctly then that letter is revealed on the hashtags like so "##e##e##" If the user guesses incorrectly then it increments an int variable named count " ++count; " String guessWord(String guess,String word, String pound) In this method, you compare the character(letter)...
Python Blackjack Game Here are some special cases to consider. If the Dealer goes over 21,...
Python Blackjack Game Here are some special cases to consider. If the Dealer goes over 21, all players who are still standing win. But the players that are not standing have already lost. If the Dealer does not go over 21 but stands on say 19 points then all players having points greater than 19 win. All players having points less than 19 lose. All players having points equal to 19 tie. The program should stop asking to hit if...
I NEED TASK 3 ONLY TASK 1 country.py class Country:     def __init__(self, name, pop, area, continent):...
I NEED TASK 3 ONLY TASK 1 country.py class Country:     def __init__(self, name, pop, area, continent):         self.name = name         self.pop = pop         self.area = area         self.continent = continent     def getName(self):         return self.name     def getPopulation(self):         return self.pop     def getArea(self):         return self.area     def getContinent(self):         return self.continent     def setPopulation(self, pop):         self.pop = pop     def setArea(self, area):         self.area = area     def setContinent(self, continent):         self.continent = continent     def __repr__(self):         return (f'{self.name} (pop:{self.pop}, size: {self.area}) in {self.continent} ') TASK 2 Python Program: File: catalogue.py from Country...
Program will allow anywhere between 1 and 6 players (inclusive). Here is what your output will...
Program will allow anywhere between 1 and 6 players (inclusive). Here is what your output will look like: Enter number of players: 2 Player 1: 7S 5D - 12 points Player 2: 4H JC - 14 points Dealer: 10D Player 1, do you want to hit? [y / n]: y Player 1: 7S 5D 8H - 20 points Player 1, do you want to hit? [y / n]: n Player 2, do you want to hit? [y / n]: y...
convert to python 3 from python 2 from Tkinter import * # the blueprint for a...
convert to python 3 from python 2 from Tkinter import * # the blueprint for a room class Room(object): # the constructor def __init__(self,name,image): # rooms have a name, exits (e.g., south), exit locations (e.g., to the south is room n), # items (e.g., table), item descriptions (for each item), and grabbables (things that can # be taken and put into the inventory) self.name = name self.image = image self.exits = {} self.items = {} self.grabbables = [] # getters...