hangman project in python

Solutions on MaxInterview for hangman project in python by the best coders in the world

showing results for - "hangman project in python"
Isabelle
26 Jan 2021
1import random
2stages = ['''
3  +---+
4  |   |           You hanged the man
5  |   |             ____________
6  O   |            |  \/    \/  |
7 /|\  |            |  /\    /\  |
8 / \  |            |     *      |
9                   |   ------   |
10=========          |____________|
11''', '''
12  +---+
13  |   |
14  O   |
15 /|\  |
16 /    |
17      |
18=========
19''', '''
20  +---+
21  |   |
22  O   |
23 /|\  |
24      |
25      |
26=========
27''', '''
28  +---+
29  |   |
30  O   |
31 /|   |
32      |
33      |
34=========''', '''
35  +---+
36  |   |
37  O   |
38  |   |
39      |
40      |
41=========
42''', '''
43  +---+
44  |   |
45  O   |
46      |
47      |
48      |
49=========
50''', '''
51  +---+
52  |   |
53      |
54      |
55      |
56      |
57=========
58''']
59words = ["in","apple","mango","good","india","priyanka","gramamr"]
60computer_choice = random.choice(words)
61
62
63display = []
64word_length = len(computer_choice)
65for _ in range(word_length):
66    display += "_"
67print(display)
68The_end = False
69lives = 6
70while not The_end:
71    if lives == 6:
72        print(stages[6])
73    guess = input("Guess a letter: ").lower()
74    for position in range(word_length):
75        letter = computer_choice[position]
76        if letter == guess:
77            display[position] = letter
78        
79    print(display)
80    if guess not in computer_choice:
81        lives -= 1
82        if lives == 0:
83            print("you lost")
84            print(stages[0])
85            The_end = True
86        elif lives == 1:
87            print(stages[1])
88        elif lives == 2:
89            print(stages[2])
90        elif lives == 3:
91            print(stages[3])
92        elif lives == 4:
93            print(stages[4])
94        elif lives == 5:
95            print(stages[5])
96    if "_" not in display:
97        The_end = True
98        print("You won")
Erica
05 Jun 2019
1
2#importing the time module
3import time
4
5#welcoming the user
6name = raw_input("What is your name? ")
7
8print "Hello, " + name, "Time to play hangman!"
9
10print "
11"
12
13#wait for 1 second
14time.sleep(1)
15
16print "Start guessing..."
17time.sleep(0.5)
18
19#here we set the secret
20word = "secret"
21
22#creates an variable with an empty value
23guesses = ''
24
25#determine the number of turns
26turns = 10
27
28# Create a while loop
29
30#check if the turns are more than zero
31while turns > 0:         
32
33    # make a counter that starts with zero
34    failed = 0             
35
36    # for every character in secret_word    
37    for char in word:      
38
39    # see if the character is in the players guess
40        if char in guesses:    
41    
42        # print then out the character
43            print char,    
44
45        else:
46    
47        # if not found, print a dash
48            print "_",     
49       
50        # and increase the failed counter with one
51            failed += 1    
52
53    # if failed is equal to zero
54
55    # print You Won
56    if failed == 0:        
57        print "
58You won"  
59
60    # exit the script
61        break              
62
63    print
64
65    # ask the user go guess a character
66    guess = raw_input("guess a character:") 
67
68    # set the players guess to guesses
69    guesses += guess                    
70
71    # if the guess is not found in the secret word
72    if guess not in word:  
73 
74     # turns counter decreases with 1 (now 9)
75        turns -= 1        
76 
77    # print wrong
78        print "Wrong
79"    
80 
81    # how many turns are left
82        print "You have", + turns, 'more guesses' 
83 
84    # if the turns are equal to zero
85        if turns == 0:           
86    
87        # print "You Lose"
88            print "You Lose
89"  
90
queries leading to this page
how to paly hangman instructions in pythonhow to make online hangman in pythonbuild the hangman game using python python how to program hangmanhangman game on pythonbasic python hangman game hangman python projectshow to make a hangman in pythonhow to make a simple hangman game in pythonmake hangman in pythonhow to make python hangmanmake a hangman game ini pythonhow to make hangman in pythonprogram hangman step by stephangman tutorial pythonmake a hangman game in pythonhangman word python packagehow to make a word gussing game using the read textile in pythonhangman python code simplehangman project in pythoncreating a hangman game in pythonpython hangmanpython project hang manhow to make hangman with pythonpython create a hangmanhangman python how do you make a hangman game using python 3fhow to code hangman in pythonhow to make a python hangman gamehow to make a hangman game in pythoncreate hangman in pythonpython game creator hangmanwhat is hangman game in pythonhow to make a hangman game using pythonhangman in pythonbuild a hangman game in pythonhow to create hangman game in pythonwords py hangman coding projects python hangmanhangman in pygamewords for hangman pythonhow to build a hangman game in pythonthe hangman game pythonhagman game pythoncrewate hangman in pythonmake a basic hang hangman game in pythonhow to make hangman game in pythonfile words py hangmanhangman python tutorialhangman python 3fhow to import hangman in pythonpython hangman gamepython hangman game codehow to draw hangman in pythonhow to make hangman stickman drawing pythoncreate a hangman game with pythonhow to write a guessing word game using the write textile in pythonhow to print hangman drwing in python correcthang man python 3 8how to make hangman on pythonhangman game in pythonhangman pseudocode pythonhangman in python tutorialhow to make a hangman game on pythonhangman game with pythonwrite a hangman for pythoncreate hangman game in pythonhangman game in python codehangman python 3 8simple hangman game pythonpython hangman gamehangman python gamemaking a hangman game in pythoncreating an easy hangman game in pythonhangama game in python codewrite a hangman game in pythonhangman words pythonpython how to make hangmanhow to build hangman in pythonhow to make hangeman in pythonpython how to make a hangman gamehangman game using pythonhangman python game made simplehangman project in python