Skip to content

Commit f5abef4

Browse files
HangMan Game
This is a 'HangMan Game' Program which was written in 'Python' Language.
1 parent f3b212f commit f5abef4

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

HangMan Game

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Program for HangMan Game.
2+
import random, HangMan_Includes as incl
3+
4+
while True:
5+
chances=6
6+
inp_lst=[]
7+
result_lst=[]
8+
name=random.choice(incl.names).upper()
9+
# print(name)
10+
[result_lst.append('__ ') for i in range(len(name))]
11+
result_str=str().join(result_lst)
12+
13+
print(f'\nYou have to Guess a Human Name of {len(name)} Alphabets:\t{result_str}')
14+
print(incl.draw[0])
15+
16+
while True:
17+
if result_str.replace(' ','')==name:
18+
print(f'\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Correct Answer: {name} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~')
19+
print(incl.won+'\a')
20+
break
21+
inp=input('\nGuess an Alphabet or a Sequence of Alphabets: ').upper()
22+
23+
if inp in inp_lst:
24+
print('......................................................................Already Tried')
25+
continue
26+
else:
27+
inp_lst.append(inp)
28+
29+
t=0
30+
indx=[]
31+
if inp in name:
32+
temp=name
33+
while temp!='':
34+
if inp in temp:
35+
indx.append(t+temp.index(inp))
36+
t=temp.index(inp)+1
37+
temp=temp[t:]
38+
else:
39+
break
40+
41+
for j in range(len(indx)):
42+
for i in range(len(inp)):
43+
result_lst[indx[j]]=inp[i]+' '
44+
indx[j]+=1
45+
i+=1
46+
47+
result_str=str().join(result_lst)
48+
print('\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Excellent~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~')
49+
print(f'\nYou have to Guess a Human Name of {len(name)} Alphabets:\t{result_str}\n')
50+
print('Tried Inputs:',tuple(sorted(set(inp_lst))))
51+
52+
else:
53+
print('\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Try Again!!!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~')
54+
print(f'\nYou have to Guess a Human Name of {len(name)} Alphabets:\t{result_str}\n')
55+
print(incl.draw[chances])
56+
chances=chances-1
57+
58+
if chances!=0:
59+
print('Tried Inputs:',tuple(sorted(set(inp_lst))))
60+
print(f'\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~You were left with {chances} Chances~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~')
61+
else:
62+
print(f'\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Correct Answer: {name} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~')
63+
print(incl.lose+'\a')
64+
break
65+
66+
try:
67+
if int(input('To play the Game Again Press "1" & "0" to Quit: '))!=1:
68+
exit('\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Thank You~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~')
69+
except:
70+
exit('\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Thank You~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~')

0 commit comments

Comments
 (0)