-
Notifications
You must be signed in to change notification settings - Fork 129
/
Copy pathhangman.py
47 lines (44 loc) · 1.19 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
47
hangman_parts = [ "head", "left arm", "torso", "right arm", "left leg", "right leg" ]
num_wrong_guesses_allowed = len(hangman_parts)
words = [
"apple",
"butterfly",
"car",
"pajama",
"kayak",
"zigzag",
"zombie",
"oxygen",
"able",
"baby",
"lock",
"ornament",
"quality",
"liquid",
"suggestion",
"weather",
"twist"
]
def draw_hangman(num_wrong_guesses):
if num_wrong_guesses > num_wrong_guesses_allowed:
num_wrong_guesses = num_wrong_guesses_allowed
hangman_characters = {
"head" : " O",
"left arm" : " /",
"torso" : "|",
"right arm" : "\\",
"left leg" : " /",
"right leg" : " \\"
}
hangman_newlines = [ "head", "right arm", "right leg" ]
output = " _____\n | |\n | "
num_newlines = 0
for i in range(num_wrong_guesses):
output = output + hangman_characters[hangman_parts[i]]
if hangman_parts[i] in hangman_newlines:
output = output + "\n | "
num_newlines = num_newlines + 1
for i in range(len(hangman_newlines) - num_newlines):
output = output + "\n |"
output = output + "____\n\n"
print(output)