63
loading...
This website collects cookies to deliver better user experience
#start with the hangman game
import time
print("-----Hangman game-----")
print("Let's play!")
time.sleep(0.5)
#the word to be guessed
word = 'techvidvan'
print("\n-----Guess the letters in the word-----")
time.sleep(0.5)
#initial guesses are none
totalGuesses = ' '
tries = 11
while(tries > 0):
#variable to count number of incorrect attempts
incorrect = 0
for letter in word:
if letter in totalGuesses:
#print the correctly guessed letter if found
print(letter)
else:
#print a dash if letter not in word
print("_")
incorrect += 1
if incorrect == 0:
#player wins
print("You Win")
print("Word is - ", word)
break
#input again if wrong letter guessed
guess = input("\nGuess a letter in the word - ")
#store guessed letters in totalGuesses
totalGuesses += guess
#if guess in not present in the word
if guess not in word:
tries -= 1
print("Wrong")
#print tries left for the player
print("You have ", + tries, 'guesses left')
if tries == 0:
print("You Lose")