-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHangman.py
55 lines (31 loc) · 847 Bytes
/
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
47
48
49
50
51
52
53
54
55
import random
answerlist=["world","look","hello","goodbye"]
random.shuffle(answerlist)
answer=list(answerlist[0])
display=[]
used=[]
display.extend(answer)
used.extend(answer)
for i in range(len(display)):
display[i]="_"
print(' '.join(display))
count=0
incorrect=5
while count<len(answer) and incorrect>0:
guess=input("Please guess a letter : ")
guess=guess.lower()
print(count)
for i in range(len(answer)):
if answer[i]==guess and guess in used:
display[i]=guess
count=count+1
used.remove(guess)
if guess not in display:
incorrect =incorrect-1
print("Sorry wrong guess.You have",incorrect,"chances left")
print(' '.join(display))
if count==len(answer):
print("You won the game")
else:
print("Game is Over")
print(answer)