Skip to content

Instantly share code, notes, and snippets.

@pranav1698
Created May 21, 2019 09:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pranav1698/3b37632d6b3b98aaa22bc229272529fb to your computer and use it in GitHub Desktop.
Save pranav1698/3b37632d6b3b98aaa22bc229272529fb to your computer and use it in GitHub Desktop.
Python-Hangman-Game
import time
import random
# Welcome
name = input('What is your name? \n')
print("Hello, " + name + " Ready for hangman!")
print(' ')
# Wait for 1 second
time.sleep(1)
print("Start Guessing!")
time.sleep(0.5)
turns = 10
words = ['chicago', 'canberra', 'mumbai', 'sydney', 'paris']
random = random.randrange(0, 4, 1)
word = words[random]
guesses = ''
failed = 0
while turns > 0:
guess = input('Make a guess?')
if guess in word:
for char in word:
if guess == char or char in guesses:
print(char, end=' ')
guesses += char
else:
print('_', end=' ')
print('\n')
if set(word) == set(guesses):
print('You won!!!')
break
else:
turns -= 1
print("Wrong! You have, "+ str(turns) + " more guesses")
failed += 1
if failed >= 3:
print('You lose')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment