forked from geekcomputers/Python
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is a 'HangMan Game' Program which was written in 'Python' Language.
- Loading branch information
1 parent
f3b212f
commit f5abef4
Showing
1 changed file
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# Program for HangMan Game. | ||
import random, HangMan_Includes as incl | ||
|
||
while True: | ||
chances=6 | ||
inp_lst=[] | ||
result_lst=[] | ||
name=random.choice(incl.names).upper() | ||
# print(name) | ||
[result_lst.append('__ ') for i in range(len(name))] | ||
result_str=str().join(result_lst) | ||
|
||
print(f'\nYou have to Guess a Human Name of {len(name)} Alphabets:\t{result_str}') | ||
print(incl.draw[0]) | ||
|
||
while True: | ||
if result_str.replace(' ','')==name: | ||
print(f'\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Correct Answer: {name} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~') | ||
print(incl.won+'\a') | ||
break | ||
inp=input('\nGuess an Alphabet or a Sequence of Alphabets: ').upper() | ||
|
||
if inp in inp_lst: | ||
print('......................................................................Already Tried') | ||
continue | ||
else: | ||
inp_lst.append(inp) | ||
|
||
t=0 | ||
indx=[] | ||
if inp in name: | ||
temp=name | ||
while temp!='': | ||
if inp in temp: | ||
indx.append(t+temp.index(inp)) | ||
t=temp.index(inp)+1 | ||
temp=temp[t:] | ||
else: | ||
break | ||
|
||
for j in range(len(indx)): | ||
for i in range(len(inp)): | ||
result_lst[indx[j]]=inp[i]+' ' | ||
indx[j]+=1 | ||
i+=1 | ||
|
||
result_str=str().join(result_lst) | ||
print('\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Excellent~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~') | ||
print(f'\nYou have to Guess a Human Name of {len(name)} Alphabets:\t{result_str}\n') | ||
print('Tried Inputs:',tuple(sorted(set(inp_lst)))) | ||
|
||
else: | ||
print('\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Try Again!!!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~') | ||
print(f'\nYou have to Guess a Human Name of {len(name)} Alphabets:\t{result_str}\n') | ||
print(incl.draw[chances]) | ||
chances=chances-1 | ||
|
||
if chances!=0: | ||
print('Tried Inputs:',tuple(sorted(set(inp_lst)))) | ||
print(f'\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~You were left with {chances} Chances~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~') | ||
else: | ||
print(f'\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Correct Answer: {name} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~') | ||
print(incl.lose+'\a') | ||
break | ||
|
||
try: | ||
if int(input('To play the Game Again Press "1" & "0" to Quit: '))!=1: | ||
exit('\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Thank You~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~') | ||
except: | ||
exit('\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Thank You~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~') |