-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHangman.py
More file actions
38 lines (33 loc) · 971 Bytes
/
Hangman.py
File metadata and controls
38 lines (33 loc) · 971 Bytes
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
#Hangman_game
#Globals
word_complete=False
lifes=8
answer="bicycle"
answer=answer.lower()
incomplete_answer=[]
#Body
for x in answer:
incomplete_answer.append("_")
print("Welcome to the Hangman game")
while(word_complete==False):
print(" ".join(incomplete_answer))
incomplete_answer=list(incomplete_answer)
print("You have "+str(lifes)+" tries")
guess=input("Guess a letter or the complete word: ")
guess=guess.lower()
for index,letter in enumerate(answer):
if letter==guess:
if letter in incomplete_answer:
print("Already said that")
incomplete_answer[index]=guess
if answer==str("".join(incomplete_answer)):
word_complete=True
print("You win!")
guess=guess.lower()
if guess in answer:
print("Nice")
else:
lifes-=1
if lifes==0:
print("Game Over")
break