create a hangman game with python


#importing the time module
import time

#welcoming the user
name = raw_input("What is your name? ")

print "Hello, " + name, "Time to play hangman!"

print "
"

#wait for 1 second
time.sleep(1)

print "Start guessing..."
time.sleep(0.5)

#here we set the secret
word = "secret"

#creates an variable with an empty value
guesses = ''

#determine the number of turns
turns = 10

# Create a while loop

#check if the turns are more than zero
while turns > 0:         

    # make a counter that starts with zero
    failed = 0             

    # for every character in secret_word    
    for char in word:      

    # see if the character is in the players guess
        if char in guesses:    
    
        # print then out the character
            print char,    

        else:
    
        # if not found, print a dash
            print "_",     
       
        # and increase the failed counter with one
            failed += 1    

    # if failed is equal to zero

    # print You Won
    if failed == 0:        
        print "
You won"  

    # exit the script
        break              

    print

    # ask the user go guess a character
    guess = raw_input("guess a character:") 

    # set the players guess to guesses
    guesses += guess                    

    # if the guess is not found in the secret word
    if guess not in word:  
 
     # turns counter decreases with 1 (now 9)
        turns -= 1        
 
    # print wrong
        print "Wrong
"    
 
    # how many turns are left
        print "You have", + turns, 'more guesses' 
 
    # if the turns are equal to zero
        if turns == 0:           
    
        # print "You Lose"
            print "You Lose
"  

Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
hangman game using python creating a hangman game in python basic python hangman game how to create hangman game in python what is hangman game in python How do you make a hangman game using python? python how to make a hangman game hangman python game made simple Python - Hangman Game how to make a python hangman game Build the Hangman Game using Python. create hangman game in python coding projects python hangman write a hangman for python how to make online hangman in python hangman pseudocode python hangman word python package hangman in pygame hangman in python create hangman in python crewate hangman in python hagman game python how to make a hangman in python make a basic hang hangman game in python file words.py hangman words.py hangman how to draw hangman in python how to import hangman in python words for hangman python program hangman step by step hangman python tutorial hangama game in python code how to paly hangman instructions in python how to make a hangman game on python make hangman in python how to make hangman stickman drawing python how to code hangman in python hangman python code simple hangman game on python how to make hangman on python how to make a hangman game using python make a hangman game ini python hangman in python tutorial write a hangman game in python How to make hangman with Python python create a hangman how to build a hangman game in python how to write a guessing word game using the write textile in python how to make a word gussing game using the read textile in python python how to program hangman python how to make hangman python hangman game hangman game with python make a hangman game in python how to make python hangman how to print hangman drwing in python correct making a hangman game in python hangman tutorial python hangman game in python hangman project in python hangman python game the hangman game python how to build hangman in python how to make a hangman game in python python hangman hangman python 3.8 hang man python 3.8 how to make hangman in python how to make hangeman in python Hangman Python ? Hangman Python hangman words python create a hangman game with python
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source