-
Notifications
You must be signed in to change notification settings - Fork 0
/
C10.py
executable file
·53 lines (46 loc) · 1.33 KB
/
C10.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
import C10_wordsforhangman
picked_word=C10_wordsforhangman.wordpicker()
def hangman(word):
wrong = 0
stages = ["",
"________ ",
"| ",
"| | ",
"| 0 ",
"| /|\ ",
"| / \ ",
"| "
]
word=word.upper()
rletters = list(word)
wletters = list()
board = ["__"] * len(word)
win = False
print("Welcome to Hangman")
while wrong < len(stages)-1:
print("\n")
msg = "Guess a letter: "
print("Enter quit to exit")
char = input(msg).upper()
if char == "QUIT":
break
if char in rletters:
cind = rletters.index(char)
board[cind]=char
rletters[cind]='$'
else:
wrong +=1
wletters.append(char)
print("You already tried: ", wletters)
print((" ".join(board)))
e = wrong + 1
print("\n".join(stages[0:e]))
if "__" not in board:
print("You win! The word was: ")
print(" ".join(board))
win = True
break
if not win:
print("\n".join(stages[0:wrong]))
print("You lose! The word was: {}.".format(word))
hangman(picked_word)