@nmakry/

# Hangman

## Hangman Game

Files
• main.py
main.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
```
```import time
import getpass
import random

def invalid():
print("")
print("INVALID INPUT")
time.sleep(sec)

def play_game(secret,sec): #the actual game
def correct_guess(guess,secretword,output):
j=[]
t=-1 #Next couple lines is modefied code from https://stackoverflow.com/questions/20039022/python-finding-more-than-one-index-in-a-list-of-letters
while True:
try:
t=secretword.index(guess,t+1)
j.append(t)
except ValueError:
break
for z in j:
output[z]=guess

def draw_hangman(attempts): #generates image of hangman [attempts = number of wrong answers (up to 9)]
def legs(at):
if at==6:
if p==10:
print("*              *")
print("* *           *")
print("*  *")
if at>=7:
if p==10:
print("*              * *")
print("* *           *   *")
print("*   *")

def rest(att):
if att in (1,2,3,4,5):
n={1: 2,2: 3,3: 5,4: 7,5: 10}
c=n[att]
if p in range(c,11):
print("*")
if p==11:
print("* *")
print("*   *")

for  p in range(1,13):
if p==1:
print("")
if attempts>=2:
if p==2:
print("* * * * * * * * *")
if attempts>=3:
if p in (3,4):
print("*               *")
if attempts>=4:
if p==5:
print("*             *   *")
print("*               *")
if attempts in (5,6,7):
if p in (7,8,9):
print("*               *")
legs(attempts)
if attempts==8:
if p==7:
print("*             * *")
print("*            *  *")
print("*               *")
legs(attempts)
if attempts==9:
if p==7:
print("*             * * *")
print("*            *  *  *")
print("*               *")
legs(attempts)
else:
rest(attempts)
else:
rest(attempts)
else:
rest(attempts)
else:
rest(attempts)
#secret = is the secret word / word = what the player already guessed
word=[]
for _ in secret:
word.append("_")
k=0
check=[] #here go all the guesses to make sure something isn't guessed twice
while True:
if secret==word:
print("")
print(word)
print("")
print("VICTORY")
break
continue
else:
print("")
print(word)
print("")
g=input("Enter Guess:")

if len(g)!=1:
invalid()
continue
if " " in g:
invalid()
continue
if g in check:
print("")
time.sleep(sec)
continue
else:
check.append(g)
u=False
if g.lower() in secret:
correct_guess(g.lower(),secret,word)
u=True
if g.upper() in secret:
correct_guess(g.upper(),secret,word)
u=True
if u:
continue
else:
k=k+1
draw_hangman(k)
if k==9:
print("")
print(secret)
print("")
print("GAME OVER")
break
time.sleep(sec)

# got this list from https://github.com/Xethron/Hangman/blob/master/words.txt
sec=0.8 #since all time delays are the same I wanted them all to be a variable so it is easeier to change it
while True:
print("")
print("1:New Game(Random Word)")
print("3:Exit Game")
x=input("Enter(1,2,3):")
if x=="2":
while True:
print("")
wordchoice=getpass.getpass("Enter secret word:")
y=False
if " " in wordchoice:
print("")
print("Only one word!")
time.sleep(sec)
continue
if len(wordchoice)<1:
invalid()
continue
alphabet="abcdefghijklmnopqrstuvwxyz"
wordlist=list(wordchoice)
for n in wordlist:
if n in alphabet.lower():
continue
if n in alphabet.upper():
continue
else:
print("")
print("Use only letters!")
time.sleep(sec)
y=True
break
if y:
continue
else:
play_game(wordlist,sec)
break
continue
if x=="1":
wordlist=list(random.choice(wordlibary))
play_game(wordlist,sec)
continue
if x=="3":
break
else:
invalid()```
Fetching token