-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhangman.py
46 lines (43 loc) · 1.64 KB
/
hangman.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import random
def hangman(word):
stages = ['',
'---------- ' ,
' | ',
' 0 ',
' /|\ ',
' / \ ',
' ',
'']
wrong = 0
board = list('_'*len(word))
wrong_letters=[]
wordlist=list(word)
print("Letter Board: " + ''.join(board))
while wrong < len(stages)-1:
guess = input("Enter a letter:")
if guess in wordlist:
board[wordlist.index(guess)] = guess
wordlist[wordlist.index(guess)]='$'
print("Correct!!")
print("---------------------------------------")
print('\n'.join(stages[0:wrong]))
print("---------------------------------------")
print("Letter Board: "+''.join(board))
print("---------------------------------------")
if '_' not in board:
print("Congratulations!! you win")
break
else :
wrong_letters.append(guess)
print("Wrong Guess...")
print("Wrong Guesses till now:",wrong_letters)
print("---------------------------------------")
print('\n'.join(stages[0:wrong]))
wrong+=1
print("---------------------------------------")
print("Letter Board: ",board)
print("---------------------------------------")
if wrong==len(stages)-1:
print("Sorry.. you lose")
list_of_words = ['india','america','russia','china','brazil','australia']
hangman(random.choice(list_of_words))