Skip to content

Commit 77eabe4

Browse files
authored
Add files via upload
1 parent d2f24f0 commit 77eabe4

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

Hangman/Hangman.py

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import random
2+
from stat import FILE_ATTRIBUTE_SPARSE_FILE
3+
4+
5+
words = ['Coffee','Cancer','Zebra','microwave','nightclub','nowadays','ovary','oxygen','pneumonia','quixotic','whomever','yachtsman','kilobyte','strength','flopping','stymied','zombie']
6+
lifes = 10
7+
8+
intro = '''
9+
Hey this is Hangman game
10+
You have to guess the correct word in 5 lifes|
11+
12+
'''
13+
word = random.choice(words).lower()
14+
noOfDash = list('_'*len(word))
15+
16+
17+
18+
def find(ltr,word):
19+
itrPlace = []
20+
x = 0
21+
if ltr in word:
22+
for i in word:
23+
if i == ltr:
24+
itrPlace.append(x)
25+
x +=1
26+
return itrPlace
27+
else:
28+
return(None)
29+
30+
def dash(list,ltr):
31+
for x in range(len(noOfDash)):
32+
if x in list:
33+
noOfDash[x]=ltr
34+
return noOfDash
35+
36+
def check():
37+
if noOfDash == list(word):
38+
return True
39+
else:
40+
return False
41+
42+
43+
44+
45+
i=0
46+
print(noOfDash)
47+
while i < lifes:
48+
letter = input("Enter the letter: ")
49+
a = find(letter,word)
50+
if a == None:
51+
i += 1
52+
print("Oops wrong word\nLifes left = {}".format(lifes-i))
53+
continue
54+
else:
55+
dash(a,letter)
56+
print(noOfDash)
57+
if check()== True:
58+
print("you won")
59+
break
60+
61+
62+
print('word was ',word)
63+

0 commit comments

Comments
 (0)