Thinking about creating a simple game in python? Yes it is really easy. Let us consider you have to create Hangman Python game. Well here we have provided you free Code of this game. Just copy and paste it into your python interpreter and enjoy the game.
How to Create Hangman Python Code Simple Way
By using this code given below you can create your own Classic Hangman python Game in a really simple manner. here is the Code:
#importing the time module
#welcoming the user
name = raw_input("What is your name? ")
print "Hello, " + name, "Time to play hangman!"
#wait for 1 second
print "Start guessing..."
#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
# if not found, print a dash
# and increase the failed counter with one
failed += 1
# if failed is equal to zero
# print You Won
if failed == 0:
# exit the script
# 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
# how many turns are left
print "You have", + turns, 'more guesses'
# if the turns are equal to zero
if turns == 0:
# print "You Loose"
print "You Loose
If you like the Code then subscribe us and share this page with your friends, keep visiting Codinglio. Cheers..!!