forked from souravjain540/Basic-Python-Programs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhangman.py
More file actions
29 lines (26 loc) · 650 Bytes
/
hangman.py
File metadata and controls
29 lines (26 loc) · 650 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
import random
guess_list = [
'samuel',
'activity',
'banana',
'school',
'python',
'programming',
'hangman',
]
print('WELCOME TO MY HANGMAN GAME\n')
cc = random.choice(guess_list).upper()
guesses = len(cc)+4
repw = ['_' for i in range(len(cc))]
while guesses > 0:
print(f'WORD: {" ".join(repw)}')
ug = input('Guess a letter:').upper()
for char in range(len(cc)):
if ug==cc[char]:
repw[char]=ug
if repw.count('_')==0:
print(f'WORD: {" ".join(repw)}')
break
print('Tries remain:',guesses-1,'\n')
guesses-=1
print('\nYou WIN🎉\n') if repw.count('_')==0 else print('\nYou LOSE💔')