-
Notifications
You must be signed in to change notification settings - Fork 0
/
Hangman.py
43 lines (40 loc) · 1.15 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
import random
def hangman():
word_list = ["dumb", "mouse", "headphones", "cologne", "musty", "musky"]
word = random.choice(word_list)
wrong = 0
stages = ["",
"________ ",
"| ",
"| | ",
"| 0 ",
"| /|\ ",
"| / \ ",
"| "
]
rletters = list(word)
board = ["__"] * len(word)
win = False
print("Welcome to Hangman")
while wrong < len(stages) -1:
print(len(stages))
print("\n")
msg = "Guess a letter"
char = input(msg)
if char in rletters:
cind = rletters.index(char)
board[cind] = char
rletters[cind] = '$'
else:
wrong += 1
print((" ".join(board)))
e = wrong + 1
print("\n".join(stages[0: e]))
if "__" not in board:
print("you win!")
print(" ".join(board))
win = True
break
if not win:
print("\n".join(stages[0: wrong]))
print("You lose! It was {}.".format(word))