-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHangman.py
More file actions
51 lines (40 loc) · 922 Bytes
/
Hangman.py
File metadata and controls
51 lines (40 loc) · 922 Bytes
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
import random
# random word
names = []
a = random.choice(names)
print(a)
# create a list for random name
name_list = []
for n in range(len(a)):
name_list.append("_")
n_list = len(name_list)
print(name_list)
# guess a letter
life=5
def guess():
g = input(":").lower()
if g.upper() in name_list:
print("Already guessed the letter")
guess()
elif g in a:
#yess g in a
for i in range(n_list):
if a[i] == g:
name_list[i] = g.upper()
print(name_list)
if "_" not in name_list:
print("End")
print("Victory")
elif "_" in name_list:
guess()
# no g not in a
elif g not in a:
global life
life -= 1
if life == 0:
print("End")
print("Limit Reached")
elif life > 0:
print(name_list)
guess()
guess()