Professional Documents
Culture Documents
Hangman Py Code
Hangman Py Code
Hangman Py Code
def hangman():
list_of_words=['hardwork','smartwork','computer','string','literal','string','tuple
','dictionary']
word=random.choice(list_of_words)
turns = 10
guessmade=''
valid_entry=set('abcdefghijklmnopqrstuvwxyz')
while len(word)>0:
main_word=''
missed=0
if main_word == word:
print(main_word)
print('you won')
break
if guess in valid_entry:
guessmade=guessmade+guess
else:
print('enter vaild character ')
guess=input()
if turns==9:
print('you have 9 more turns left')
print('--------------------------')
if turns==8:
print('you have 8 more turns left')
print('--------------------------')
print(' o ')
if turns==7:
print('you have 7 more turns left')
print('--------------------------')
print(' o ')
print(' | ')
if turns==6:
print('you have 6 more turns left')
print('--------------------------')
print(' o ')
print(' | ')
print(' / ')
if turns==5:
print('you have 5 more turns left')
print('--------------------------')
print(' o ')
print(' | ')
print(' / \ ')
if turns==4:
print('you have 4 more turns left')
print('--------------------------')
print(' o ')
print(' |- ')
print(' / \ ')
if turns==3:
print('you have 3 more turns left')
print('--------------------------')
print(' o ')
print(' -|- ')
print(' / \ ')
if turns==2:
print('you have 2 more turns left')
print('--------------------------')
print(' o | ')
print(' -|- ')
print(' / \ ')
if turns==1:
print('last chance !')
print('--------------------------')
print(' o_| ')
print(' -|- ')
print(' / \ ')
if turns==0:
print('GAME OVER')
print('you losse')
print('The Word is : ',word)
break
print("Goodluck",Name,"!!")
print("------------------")
print("try to guess the right word in less than 10 attempts ")
hangman()