Skip to content

Instantly share code, notes, and snippets.

@hackerdem
Created May 12, 2016 07:36
Show Gist options
  • Save hackerdem/edf67cd468caf03033768586793283f6 to your computer and use it in GitHub Desktop.
Save hackerdem/edf67cd468caf03033768586793283f6 to your computer and use it in GitHub Desktop.
simple hangman game in python programming language
import random,time,os,hangman_pic
def exit_question():
answer=input("do you wanna play again.Y/N:")
if answer.upper()=="N":
print("See you later bro")
time.sleep(2)
exit()
else:
game()
def chose_letter(num):
question=random.randint(0,num)
return question
def interruption():
print("Bye")
time.sleep(1)
exit()
def game():
right,counter=3,1
guess=" "
newgame=False
while (newgame is False):
life=7
question=chose_letter(len(wordlist1)-1)
charlist=list(wordlist1[question])
print ("Welcome to hangman game!!")
time.sleep(1.5)
while life>0 and right>0:
try:
if len(letterlist)==len(set(wordlist1[question])):
exit_question()
os.system('cls')
for char in wordlist1[question]:
if char not in letterlist:
print("_ ", end=" ")
else:
print(char+" ",end=" ")
letter=input("\n\nMake your guess or choose letter {}: ".format(8-life) )
if len(letter)==1 and letter in charlist:
letterlist.append(letter)
print("Great job!!")
time.sleep(1)
elif len(letter)==1 and letter not in charlist:
life=life-1
print ("you wasted,remaining joker {}".format(life))
print(hangman_pic.HANGMAN[7-life])
time.sleep(3)
elif len(letter)>1 and letter!=wordlist1[question]:
guesslist.append(letter)
right=right-1
print("Wrong mate!!try again,remaining guess {}".format(right))
time.sleep(3)
except KeyboardInterrupt:
print("h")
exit_question()
if __name__=="__main__":
global wordlist1
wordlist1=['erdem','computer','rifle','missing','poetr','accountant']
guesslist,letterlist,charlist=[],[],[]
game()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment