-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathHangman.py
More file actions
57 lines (37 loc) · 964 Bytes
/
Hangman.py
File metadata and controls
57 lines (37 loc) · 964 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
48
49
50
51
52
53
54
55
56
57
import random
movies = ('LAGAAN', 'HIGHWAY', 'THOR', 'DANGAL', 'NEWTON')
c_m = random.sample(movies,1)
k = '*' * len(c_m[0])
print(k)
lap = {}
for i in range(len(c_m[0])):
if c_m[0][i] not in lap.keys():
j = list()
j.append(i)
lap[c_m[0][i]] = j
else:
j = lap[c_m[0][i]]
j.append(i)
lap[c_m[0][i]] = j
score = 10
print(f'Score = {score}')
while score > 0 and '*' in k:
letter = input("Guess a letter:")
if letter in lap.keys():
n = lap[letter]
for p in n:
k = k[:p]+letter+k[p+1:]
score = score+3
print('correct guess')
print(k)
print(f' Score= {score}')
lap.pop(letter)
else:
score = score-2
print('incorrect guess')
print(k)
print(f'Score={score}')
if '*' not in k:
print("YOU WON ")
else:
print("YOU LOOSE")