-
Notifications
You must be signed in to change notification settings - Fork 6
/
hangchicken.py
120 lines (110 loc) · 1.68 KB
/
hangchicken.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
PROTOTYPE = """
┏━━┑
┃ O>
┃>╦╧╦<
┃ ╠═╣
┃ ╨ ╨
┻━━━━
"""
STEPS = [
"""
┏━━┑
┃
┃
┃
┃
┻━━━━
""",
"""
┏━━┑
┃ O
┃
┃
┃
┻━━━━
""",
"""
┏━━┑
┃ O>
┃
┃
┃
┻━━━━
""",
"""
┏━━┑
┃ O>
┃ ╔╧╗
┃ ╚═╝
┃
┻━━━━
""",
"""
┏━━┑
┃ O>
┃>╦╧╗
┃ ╚═╝
┃
┻━━━━
""",
"""
┏━━┑
┃ O>
┃>╦╧╦<
┃ ╚═╝
┃
┻━━━━
""",
"""
┏━━┑
┃ O>
┃>╦╧╦<
┃ ╠═╝
┃ ╨
┻━━━━
""",
"""
┏━━┑
┃ O>
┃>╦╧╦<
┃ ╠═╣
┃ ╨ ╨
┻━━━━
"""
]
MIN_LENGTH = 3
MAX_LENGTH = 8
with open('words1000.txt') as f:
words = [line.strip() for line in f]
words = [w for w in words if MIN_LENGTH <= len(w) <= MAX_LENGTH]
words = [w for w in words if all('a' <= c <= 'z' for c in w)]
import random
word = random.choice(words)
step = 0
guessed = set()
def show():
print(STEPS[step])
chars = [c if c in guessed else "_" for c in word]
print(" ", " ".join(chars))
print()
print("guessed:", " ".join(guessed))
while True:
show()
c = input("pick a letter: ")
if len(c) != 1 or c < 'a' or c > 'z':
print("a lowercase letter!")
continue
if c in guessed:
print("you already guessed that one!")
continue
guessed.add(c)
if c not in word:
step += 1
if step == len(STEPS) - 1:
show()
print("YOU LOSE, the word was", word)
break
if all(c in guessed for c in word):
show()
print("YOU WIN!!")
break